Phonegap: GCM Push Notification registration call returns OK but device is not even connected to the internet

后端 未结 1 573
粉色の甜心
粉色の甜心 2021-01-22 04:40

I have followed this tutorial and I have the following code:

onDeviceReady I execute:

var pushNotification = window.plugins.pushNotification;
pushNotific         


        
1条回答
  •  清歌不尽
    2021-01-22 05:20

    1. register

      When you call pushNotification.register():

      • successHandler is called if there is no error in parsing your ecb and senderID. Your senderID and application are registered with GCMRegistrar.
      • errorHandler is called only if there is a JSON error while parsing the ecb or senderID

      Once your setup is correct, your errorHandler will probably never be called.

      From the docs, you have to call the register method every time you start the application. This will not create duplicate registrations. The plugin will manage all that itself.

    2. onNotificationGCM

      Only called when:

      • You receive a notification from GCM.
      • Your application is successfully registered with GCMRegistrar
    3. GCMRegistrar

      • Returns registration ID (for your application and senderID) if already registered.
      • If not, it registers your application and senderID and then returns registration ID. This requires an Internet connection (AFAIK)

      So when you call pushNotification.register the first time, if you are not connected to the Internet, PushPlugin returns OK but GCMRegistrar has no registration ID to return to you.

    0 讨论(0)
提交回复
热议问题