Cordova OneSignal Plugin won't getIds properly

▼魔方 西西 提交于 2021-01-28 22:59:02

问题


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:

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

回答1:


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



来源:https://stackoverflow.com/questions/40642793/cordova-onesignal-plugin-wont-getids-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!