if it works for you, keep it
But I doubt it, the iOS and Android snippets are different. I posted the ones that worked for me higher up the thread.
It works! i did exactly what you did
Got them!
Here are the ones that worked for me finally:
iOS
/* wk.bridge.min.js | v0.2 */
(function(){if(window.isIOS){return}window.isIOS=function(){return navigator&&navigator.userAgent&&(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent))}}());
(function(){if(window.bridge){return}window.bridge=function(){var callbacks=[],callbackID=0,registerHandlers=[];document.addEventListener("PacificDidReceiveNativeCallback",function(e){if(e.detail){var detail=e.detail;var id=isNaN(parseInt(detail.id))?-1:parseInt(detail.id);if(id!=-1){callbacks[id]&&callbacks[id](detail.parameters,detail.error);delete callbacks[id]}}},false);document.addEventListener("PacificDidReceiveNativeBroadcast",function(e){if(e.detail){var detail=e.detail;var name=detail.name;if(name!==undefined&®isterHandlers[name]){var namedListeners=registerHandlers[name];if(namedListeners instanceof Array){var parameters=detail.parameters;namedListeners.forEach(function(handler){handler(parameters)})}}}},false);return{"post":function(action,parameters,callback,print){var id=callbackID++;callbacks[id]=callback;if(window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.pacific){window.webkit.messageHandlers.pacific.postMessage({"action":action,"parameters":parameters,"callback":id,"print":print||0})}},"on":function(name,callback){var namedListeners=registerHandlers[name];if(!namedListeners){registerHandlers[name]=namedListeners=[]}namedListeners.push(callback);return function(){namedListeners[indexOf(namedListeners,callback)]=null}},"off":function(name){delete registerHandlers[name]}}}()}());
console.log('window loaded');
var id;
function getOneSignalToken() {
window.bridge.post('onesignaltoken', {}, (results, error) => {
id = results.token;
})
}
getOneSignalToken();
setTimeout(function codeAddress() {
bubble_fn_1(id);
},1000);
Android:
function getOneSignalToken() {
alert("RegisterId:" + android.getOneSignalRegisteredId() );
}
var token; token = android.getOneSignalRegisteredId();
bubble_fn_2(token)
They were copied from various places from this post, which Iāve now lost track of
Thank you again to everybody for your help!
Hi @mvandrei
I tried your plugin and after trying everything on this page , IāM unable to have any notifications on web or mobileā¦
In fact I never have the prompt of notification or anythingā¦
Do the bridge JavaScript change anyhow ?
Troubleshooting starts with checking your devices are actually assigned a playerid in onesignal. Is this the case?
Hi Vincent! No, the javascript returns nothing, and on my OneSignal panel, no user has been addedā¦
Does your app prompt to allow to send notifications? At that point (given that your onesignal and firebase settings are correct in your app (not the bubble app)) the device should get registered in onesignal.
is this iOS or Android?
No, It not even prompt me for notifications. However, here is the thing, Iām trying to do it in the case of Progressive webapp (i.e. added to the home screen app), so itās not wrapped into a webview.
Neverthelees, Iām also trying to get web notification in Chrome desktop with no luck tooā¦
Sounds like a problem with the browser notification setup within onesignal? I havenāt setup browser notifications yetā¦
Okā¦to understand: have you set up notifications only for apps that you have published on stores through webview?
Yes. I have looked at browser notifications but I havenāt implemented this. But since the devices are not getting registered with onesignal I think the issue is with not having onesignal webpush setup correctly.
Rightā¦thanks for the help! I donāt reallt see what can be missing in my Onesignal config Looks pretty easy, just to add a script in the headerā¦but still nothing
Yeah, Iād imagine youād be able to figure that out! Is there another site you can test it with? Plain html or wordpress? Sorry, canāt help you out further as I havenāt tried this yet.
Unfortunately notā¦just downloaded firefox andā¦itās working here! So I need to understand why chrome is not triggering the promptā¦
Could it be the popup blocker?
Well done! it was the popup blocker!
Now I need to effectively pass the playerID to Bubble. As my javascript still returns nothing
If someone get stucked too, Got the playerID back with this JS :
OneSignal.isPushNotificationsEnabled(function(isEnabled) {
if (isEnabled) {
// user has subscribed
OneSignal.getUserId( function(userId) {
console.log('player_id of the subscribed user is : ā + userId);
// Make a POST call to your server with the user ID
});
}
});
on what platform?
If you want to get it from mobile, you need that wrapper from SuperView. it has the code implemented and the JS is adapted to that code to get it.
Canāt say it will work for other wrappers.
As for desktop browsers, you need to configure BOTH options Safari AND chrome&firefox.