gpt4 book ai didi

android - 手机间隙 : GCM Push Notification registration call returns OK but device is not even connected to the internet

转载 作者:行者123 更新时间:2023-11-29 01:35:08 24 4
gpt4 key购买 nike

我关注了this tutorial我有以下代码:

onDeviceReady 我执行:

var pushNotification = window.plugins.pushNotification;
pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"824841663931","ecb":"app.onNotificationGCM"});

处理程序:

// result contains any message sent from the plugin call
successHandler: function(result) {
alert('Callback Success! Result = '+result)
},

errorHandler:function(error) {
alert(error);
},

onNotificationGCM: function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Regid " + e.regid);
alert('registration id = '+e.regid);
localStorage.regid = e.regid
}
break;

case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = '+e.message+' msgcnt = '+e.msgcnt);
break;

case 'error':
alert('GCM error = '+e.msg);
break;

default:
alert('An unknown GCM event has occurred');
break;
}
}

如果我的设备在我第一次打开该应用程序时已连接到互联网,则此代码可以完美运行。

如果我的设备未连接,则调用 successHandler 并显示“OK”并且永远不会调用 onNotificationGCM。这正常吗?

我原以为注册会失败并使用 e.event = 'error' 调用 errorHandler 或 onNotificationGCM,这样我就可以推迟注册,但这并没有发生。

如果有任何帮助,我将不胜感激。

最佳答案

  1. 注册

    当您调用 pushNotification.register() 时:

      如果在解析您的 ecbsenderID 时没有错误,将调用
    • successHandler。您的 senderID 和应用程序已注册 GCMRegistrar .
    • errorHandler 只有在解析 ecbsenderID
    • 时出现 JSON 错误时才会被调用

    一旦您的设置正确,您的 errorHandler 可能永远不会被调用。

    来自docs ,每次启动应用程序时都必须调用 register 方法。这不会创建重复注册。该插件将自行管理所有这些。

  2. onNotificationGCM

    仅在以下情况下调用:

    • 您会收到来自 GCM 的通知。
    • 您的应用程序已成功注册到 GCMRegistrar
  3. GCM注册商

    • 如果已经注册,则返回注册 ID(用于您的应用程序和 senderID)。
    • 如果不是,它会注册您的应用程序和 senderID,然后返回注册 ID。这需要互联网连接(据我所知)

    所以当你第一次调用pushNotification.register时,如果你没有连接到互联网,PushPlugin返回OK但是GCMRegistrar没有注册ID返回给你.

关于android - 手机间隙 : GCM Push Notification registration call returns OK but device is not even connected to the internet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28748903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com