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

YES!

Pieced some things together from other bits of js and got it to work. Use this code for Android:

var token; token = android.getOneSignalRegisteredId();
bubble_fn_x(token)
2 Likes

I guess itā€™s in the bubble app only orā€¦? :thinking:
Thinking to implement this plugin as well.

When the javascript runs but cannot get the playerid (because Iā€™m not accessing through Android), it throws a lot of errors.

I fixed it by adding another condition (page width =<768 but the best would probably be to recognize the device/os. I think there might be a plugin that does thatā€¦

Does anyone have the playerid working on iOS?

I got the code from the superview devs and it sort of matches what @mvandrei posted, but it just doesnā€™t pick up the IDā€¦ :frowning:

I have it working in iOS, but still struggling with Android and I havenā€™t tried to combine everything on a single page that will work for Android AND iOS.

Below is code snippet that I use in a ā€œrun javascriptā€ action on page load ā€œif current userā€™s OneSignal player id is emptyā€.

Donā€™t forget to add the javascript to bubble element on the page. *I made sure that it was in a group that was visible on page load.

Finally, trigger a custom event to make changes to the user to set the javascript to bubble elements value as the current userā€™s player id.

/* 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]&&callbacksid;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);
1 Like

Yeah thatā€™s the same code Iā€™m using that doesnā€™t work for me.
I have Android working and for both to work the player id field should be a list as a user can have multiple devices.

Is it working from a virtual device in xcode or a connected device? I have an iPad connected and it receives notifications so that shouldnā€™t be it.

Iā€™ll try with disabling the Android part firstā€¦ Strange stuff!

The only thing I can think of is that I did something wrong with the provisioning profile or signing certificates even though they look installed correctly and onesignal doesnt give an error.

I can send push notifications to the device so at least that worksā€¦

EDIT 2
OK I give up. Iā€™ve spent far too much time on this myself without any result :frowning:

I recreated the entire workflow in a new app that is completely empty but still no luck. The player id will not get populated with the provided iOS js code.

Iā€™m now looking to pay someone to get this to work for me. If you know or are that person, please PM me. Thanks.

EDIT 3
notā€¦givingā€¦upā€¦theā€¦noā€¦coderā€¦struggleā€¦isā€¦real

I found the next clue:

basically, there is an issue with the syntax it. I fixed that and when I post the following in an html element on the page, I get the ID on click:
function getOneSignalToken() {

    window.bridge.post('onesignaltoken', {}, (results, error) => {

        $('#onesignal_token').html(results.token)

    })

}

HTML:

                        <p id="onesignal_token"></p>

                        <div class="read-more">

                            <a id="get_onesignal_token" class="btn btn-primary" onClick="getOneSignalToken()">Get OneSignal player id</a>

                        </div>

Now, my dumb ass needs to figure out how to get it in the bubble elementā€¦

SUCCESS!
I dont think Iā€™ve ever been this happy to see a random string of characters appear on my screenā€¦ anyway, this is the code I used in the js element:

/* 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]&&callbacksid;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]}}}()}());

function getOneSignalToken() {
window.bridge.post(ā€˜onesignaltokenā€™, {}, function(results, error){
id = results.token;
})
}
getOneSignalToken();
setTimeout(function codeAddress() {

bubble_fn_222(id);

    },1000);

Behold, glorious playerIDā€™s.

Now, I think the condition for updating the current user should not be when playerid is empty because a user can have multiple devices or new devices. So I now have three different fields for web, android and ios. I think it should update only when its empty or the stored value is different from the latest retrieved id. It will make it run each time the page is loaded but if I can get access to the type of device, we can make sure it only runs the js element and user update for specific devices.

2 Likes

Hello @vincent56
Im unable to get the playerid for android using (superview).

Im using your code:

var token;
token = android.getOneSignalRegisteredId();
bubble_fn_2(token)

But nothing.
Any idea?
Thanks.

Could be a lot of things. Better to share as much detail as you can about the work flow

@vincent56 Can you please share with me your custom event, the event that loads on page (or whatever) and executes the javascript code and the javascript element?

Actually i have this:

Thanks!

Did you fix the problem? I am exactly in the same configuration ā€¦and doesnā€™t work

Here is what Iā€™m doing to set the Android player ID. It works to capture the playerID on emulator devices running in Android Studio 3.0.1, but I havenā€™t tried it with any REAL devices.

Iā€™m using the same code that you have shown above.
Here are the workflows that Iā€™m using:


Also, check to make sure that your javascript to bubble element is in a group that is visible on page load.

1 Like

Hi @mvandrei ,
Would it be possible to add the ability to set the target url globally or leave it blank without triggering a native app to open the blank url inside? I merely want users to tap on the notification and be taken to the app.
Iā€™ve noticed that leaving the url blank with this plugin seems to trigger the default Superview ā€œinternet not availableā€ page, but I didnā€™t seem to notice this with The CoBubble plugin

1 Like

Leaving it blank will load the html that is inside the www folder that comes with the wrapper.You can change that out to whatever you want but why would you leave it blank? That way you can never reference your Bubble app nor get the user to the app when they click a notification from their device.

Hey,

Sorry for the late reply. Happy Holidays past and future to all.
What exactly do you want to do?
I am really confused.

Has anyone figured out to load documents in the webview? I can click on a pdf for example and it opens it in the app, but there is no button to go back to the app so youā€™d have to close it and open the app again. I could swear I saw a ā€˜doneā€™ button once, but its definitely not there now.

Hi @mvandrei, thanks for the awesome plugin. I am however not having success with it. Iā€™ve configured it for my web app. Using WebApp YouTube instructions. But I every time I go to my website, I do not get a prompt.

I have a pro account so Iā€™m fully HTTPS. Are you aware of the plugin conflicting with other plugins?

I just canā€™t figure out why it wonā€™t work for me

1 Like

Thank you for this plugin @mvandrei! Itā€™s been very helpful and works great. The one issue that I run into is that it appears to send a ā€œ/nullā€ url field, even when you leave the url field blank. My bubble app serves as a back end for a native Android app (using Dropsource). When the url is forced, it attempts to automatically open the browser on the phone.

I agree with @stvnsnthn when he said the following:

OneSignal makes adding a LAUNCH URL optional like your plug-in does, but when it is left blank, it doesnā€™t attempt to open the browser when the notification is tapped on a mobile phone. Instead, tapping the notification opens into the native app when LAUNCH URL is left blank.

EDIT: SOLVED
So I went back and tried leaving a ā€œspaceā€ instead of a completely blank url field. Just literally hit the space bar one time in the url field and didnā€™t try to open a browser to a ā€œnullā€ url anymore.

2 Likes

@jamesonvparker @stvnsnthn
Okay, so if I got this right, youā€™re talking about the LAUNCH URL
Well, that is a feature that you can still use in superview.
You need to search and define the URL Scheme, change it from superview to WHATEVER.
Further more, you can set that each URL that contains your MAIN URL to be opened inside the wrapper so a URL like https://yourmainurl.bubbleapp.is/whateverpage will open your app upon tapping on the notification, on the whateverpage instead of index page.
And you can set that any other URL besides your main URL, to be opened in safari/pop-up.
To do so, you need to use the following scheme on onesignal at LAUNCH URL:
ā€œcustomurlscheme://ā€ + ā€œyour main URL without https or wwwā€ so in our example with:
whatever://yourmainurl.bubbleapp.is/whateverpage
this will make the app to open http://yourmainurl.bubbleapp.is/whateverpage instead of http://yourmainurl.bubbleapp.is/index

That is valid of iOS only.
For Android is a bit more complicated, OF COURSE. I will try to explain it tomorrow.

2 Likes

@mvandrei @vincent56
Jamesonā€™s discovery of tapping the spacebar in the URL field worked for me with the desired results.

I use ā€œpage is loadedā€ conditions and lots of conditional formatting to update what a user sees in the app/web when their data changes and forcing a page to reload whenever a push notification was received was causing unwanted delays. For example, visible counts on a userā€™s pending information would update prior to the user getting the notification that the info had been updated probably due to the bubble database being modified slightly faster than the API call to OneSignal to send the Push Notification.

I realize that I could probably send parameters in this URL to accomplish something similar, but that would require addressing a lot of other areas that I donā€™t really want to deal with right now.

Anyway, love the plugin, the OneSignal API is awesome and it appears that no changes are necessary to address my original concern.

1 Like

Hey @vincent56 thanks a lot for sharing what worked for you!

I wanted to clarify about the snippet that finally worked for you - the same snippet worked with both the iOS and Android SuperView wrappers?

Iā€™m using the snippet and the only thing I changed is the bubble_fn suffix, which is ā€œ1ā€ rather than ā€œ222ā€ in my app. (But like all the others Iā€™m still not getting any Player IDs in my database.)

Thanks a lot in advance for any help!