Proper Sequence to Get Registration Token for Gcm Push Notification on iOS? Is Gcm Unreliable

Proper sequence to get registration token for GCM push notification on iOS? Is GCM unreliable?

Is the call to connectWithHandler: in applicationDidBecomeActive: necessary if I am only interested in receiving GCM push messages and not send them upstream?

Yes, connectWithHandler is necessary regardless as its prime purpose is to make connection with GCM endpoint.

If answer to (1) is yes, in the completion handler of that method, if an error occurs, and I do not have the GCM token at that point, should I try to get a token again? (i.e. call tokenWithAuthorizedEntity?)

So the way it should work is you check for errors while you are requesting the token itself and retry with exponential back-off if the request fails. More info here. Also, read the note here. Now, if you still want to re-invoke the GGLInstanceIDTokenHandler at any point you should also implement deleteTokenWithAuthorizedEntity before getting a new token.

When should the startWithConfig be called? Before getting a GCM token or after?

In your AppDelegate.m you should invoke the GGLInstanceID shared instance using startWithConfig method. Essentially in GGLINstanceID.h class, it should first get an Instance ID; then authorize the project as Authorized Entity and then get a Registration Token through the iid service. See the detailed implementation for GGLInstanceID.h class here.

Hope this answers help!

EDIT

Does this answer your question? Gist of it is, make sure the Bundle Identifier for your target is the same as the BUNDLE_ID in the info.plist file.

Hopefully this resolves the error, if not post what happened when you test it and we can go from there. :)

ios Swift GCM registration token nil

I think there is nothing wrong with your code, as this is the correct way to implement Cloud Messaging on iOS Client.

Some tricky parts that you might have missed are the configuration of the Provisioning APNs SSL Certificates

  1. Create your App ID with Push Notifications ON
  2. Create your SSL Certificate
  3. Download and run it in order to be added to the Provisioning Profile
  4. To make sure that your provisioning profile has this certificate go to Xcode -> Preferences -> Account -> Your Apple ID -> Your Team -> View Details -> Download All.

This will refresh your certificates, and then go to your target, choose the correct team and run it. Hopefully it should work :)

Structure of GCM token

I've tested this out for Android before and concluded that:

<first_part>:<second_part>

The first part is the ID for the app instance, which is why calling getId() returns the same value:

Returns a stable identifier that uniquely identifies the app instance.

and the second part is the actual token for the corresponding authorized entity - i.e. sender project. Note that its possible for two different tokens to be generated from the same device, provided you are usimg multiple senders.



Related Topics



Leave a reply



Submit