科尔多瓦OneSignal插件无法正确获取ID [英] Cordova OneSignal Plugin won't getIds properly

查看:113
本文介绍了科尔多瓦OneSignal插件无法正确获取ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cordova的onesignal插件上遇到了一个小问题.当我第一次在wifi上运行该应用程序时,如果我打开移动数据,它将无法获取用户的ID,但在wifi上也能正常运行.

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:

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

推荐答案

当Google Play服务无法连接以获取推送通知所需的注册ID时,会从Google Play服务返回 SERVICE_NOT_AVAILABLE .如果您的手机连接正常,则您的wifi网络可能会阻止与Google的连接.

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.

有关更多详细信息,请参见以下堆栈溢出答案. https://stackoverflow.com/a/18325226/1244574

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

这篇关于科尔多瓦OneSignal插件无法正确获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆