1

I got a small problem with the onesignal plugin for cordova. When I'm running the app for the first time on wifi it won't get user's ids if I switch on mobile data it works just fine, after this works on wifi too.

This is the error i get on onesignal debugger:

enter image description here

Index.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>My App</title>
</head>
<body>
Test
</body>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</html>

Index.js

var app = {

    initialize: function()
    {
        this.bindEvents();
    },
    dump: function (obj) {
        var out = '';
        for (var i in obj) {
            out += i + ": " + obj[i] + "\n";
        }

        alert(out);
    },
    bindEvents: function()
    {
        document.addEventListener('deviceready', this.onDeviceReady, false);    
    },
    onDeviceReady: function()
    {
        app.receivedEvent('deviceready');
    },
    receivedEvent: function(id)
    {
        alert('init');
        window.plugins.OneSignal
    .startInit('onesignalid', 'googleproject')
    .inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
    .handleNotificationOpened(app.notificationOpenedCallback)
    .endInit();
    app.getIds();
    },
    getIds: function()
    {
        window.plugins.OneSignal.getIds(function(ids){
            app.dump(ids);
            $.post('http://example.com/app_register_notif', {uid:'4764',onesignalid: ids.userId,onesignaltoken: ids.pushToken});
        });
    }
};

app.initialize();
SimpApp ro
  • 21
  • 3

1 Answers1

0

The SERVICE_NOT_AVAILABLE is returned from Google Play services when it can't connect to get a registration id needed for push notifications. Your wifi network might be blocking a connection to Google if your cell connection works fine.

See the following stack overflow answer for more details. https://stackoverflow.com/a/18325226/1244574

Community
  • 1
  • 1
jkasten
  • 3,899
  • 3
  • 32
  • 51