FORUM COMMUNITY IDEAS SHOWCASE LEARNING CENTER

OneSignal FREE plugin for FREE and UNLIMITED Push Notifications 📱


#83

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.


#84

It works! i did exactly what you did


#85

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!


#86

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 ?


#87

Troubleshooting starts with checking your devices are actually assigned a playerid in onesignal. Is this the case?


#88

Hi Vincent! No, the javascript returns nothing, and on my OneSignal panel, no user has been added…


#89

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?


#90

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.


#91

Neverthelees, I’m also trying to get web notification in Chrome desktop with no luck too…


#92

Sounds like a problem with the browser notification setup within onesignal? I haven’t setup browser notifications yet… :frowning:


#93

Ok…to understand: have you set up notifications only for apps that you have published on stores through webview?


#94

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.


#95

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


#96

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.


#97

Unfortunately not…just downloaded firefox and…it’s working here! So I need to understand why chrome is not triggering the prompt…


#98

Could it be the popup blocker?


#99

Well done! it was the popup blocker!


#100

Now I need to effectively pass the playerID to Bubble. As my javascript still returns nothing


#101

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
});
}
});


#102

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.