Hi @mvandrei
Iāve found that by changing the following line from:
if(device.ios()){
to:
if (window.isIOS()) {
Allows for the script to get the PlayerID (when running through Superview on Android) correctly. Previously, that was erroring for me, but now it works on both platforms. Not sure if that could be something to do with the device I was using or not but thought it was worth mentioning anyway.
Trying to see JavaScript errors when running through Superview I found was a little tricky so by adding this function into the script, will make any errors popup as an alert, which just makes debugging the script a little easier thatās all. It can be removed afterwards.
window.onerror = function(msg, url, linenumber) {
alert('Error message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);
return true;
}
The JS script which Iām currently using at the moment and works for me on both devices, currently looks like thisā¦
(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]
}
}
}()
}());
//shows any errors as an alert
window.onerror = function(msg, url, linenumber) {
alert('Error message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);
return true;
}
function getOneSignalToken() {
window.bridge.post('onesignaltoken', {}, (results, error) => {
id = results.token;
})
}
if (window.isIOS()) {
getOneSignalToken();
console.log("its ios");
} else {
console.log("its not ios");
id = android.getOneSignalRegisteredId();
}
setTimeout(function codeAddress() {
bubble_fn_1(id);
}, 1000);
I hope it helps somewhat.