繁体   English   中英

Cordova OneSignal插件无法正常使用

[英]Cordova OneSignal Plugin won't getIds properly

我遇到了一个关于cordova的onesignal插件的小问题。 当我第一次在wifi上运行应用程序时,如果我打开移动数据就可以正常运行该应用程序,这也适用于无线网络。

这是我在信号调试器上遇到的错误:

在此输入图像描述

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM