My native app communicates to my bubble web app through JS bridging. I have set this up for OneSignal push notifications.
i now have a native QR scanner implemented in my app but I need to publish the scanned value into a Bubble element. I’m trying to copy the OneSignal code, but I cannot figure it out.
This one is for onesignal:
function getOneSignalToken() {
window.bridge.post(‘onesignaltoken’, {}, function(results, error){
id = results.token;
})
}
getOneSignalToken();
setTimeout(function codeAddress() {
bubble_fn_222(id);
},1000);
This is the QR script that I need to add the javascript to bubble part to.
function scanQR() {
window.bridge.post(‘scanqr’)
var qrHandler = window.bridge.on(‘qr_scan_data’, (parameters)=> {
$(‘#qr_string’).html(parameters.result)
})
}
@vincent56, so from your provided code, parameters.result is the value that you need to pass to bubble.
So add a bubbletojavascript element and give it suffix say, qrvalue
So your run javascript action will become like below:
function scanQR() {
window.bridge.post(‘scanqr’)
var qrHandler = window.bridge.on(‘qr_scan_data’, (parameters)=> {
bubble_fn_qrvalue(parameters.result)
})
}
scanQR();
Yes if you’re using the first code. Basically you declared a function called scanQR. So you need to call the function for it to execute. You don’t need to declare the function and call it in this case, you can simply just write the functions statement, hence the reason i propose the second approach.
hm ok. So this code basically does two things: start the scanner and receive the scanned result from the native app.
Would you have any idea why the combined code won’t fire the camera and separating starts indeed the code? But then I need to change the jstobubble code so it only picks up the result or something…
In plain html it works perfectly. Adding the bubble stuff makes it kind of break at the moment.
I had hoped this would work, but it doesnt start the scanner from the jstobubble element action.
function scanQR() {
window.bridge.post('scanqr')
var qrHandler = window.bridge.on('qr_scan_data', (parameters)=> {
bubble_fn_222(parameters.result);
})
}
What I don’t understand is that running this code in a plugbubble custom code block will actually run the scanner, but this element doesnt have the ability to publish the results in a Bubble compatible way…
How are you calling the code? Do you have a button that say on click you do a run javascript action with the code?
can you add this line before the bubble_fn line and lets see if the function gets called.
console.log("This is the result " + parameters.result)
Then check the console to see if this line got executed.
Oh sorry i misunderstood you all this while.
I thought you were running on the web not in an app.
I actually don’t know anything about this js bridging. so all my answers are purely based on the code you provided and how to get the value into bubble.