FORUM COMMUNITY IDEAS SHOWCASE LEARNING CENTER

OneSignal FREE plugin for FREE and UNLIMITED Push Notifications 📱


#61

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)

#63

I guess it’s in the bubble app only or…? :thinking:
Thinking to implement this plugin as well.


#64

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…


#65

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:


#66

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

#67

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.


#68

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.


#69

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


#70

@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!


#71

Did you fix the problem? I am exactly in the same configuration …and doesn’t work


#72

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.


#73

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


#74

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.


#75

Hey,

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


#76

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.


#77

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


#78

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.


#79

@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.


#80

@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.


#82

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!