OneSignal FREE plugin for FREE and UNLIMITED Push Notifications šŸ“±

if it works for you, keep it :slight_smile:
But I doubt it, the iOS and Android snippets are different. I posted the ones that worked for me higher up the thread.

1 Like

It works! i did exactly what you did

2 Likes

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&&registerHandlers[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 :joy:

Thank you again to everybody for your help!

5 Likes

Hi @mvandrei

I tried your plugin and after trying everything on this page , Iā€™M unable to have any notifications on web or mobileā€¦ :sob:
In fact I never have the prompt of notification or anythingā€¦
Do the bridge JavaScript change anyhow ?

2 Likes

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ā€¦ :frowning:

1 Like

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.

1 Like

Rightā€¦thanks for the help! I donā€™t reallt see what can be missing in my Onesignal config :frowning: 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ā€¦

1 Like

Could it be the popup blocker?

1 Like

Well done! it was the popup blocker!

1 Like

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.

1 Like