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
- Create your App ID with Push Notifications ON
- Create your SSL Certificate
- Download and run it in order to be added to the Provisioning Profile
- 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
iOS Today Extension with Core Data
How to Select Table View Row Selection with Custom Checkbox Button
Uidocumentinteractioncontroller Does Not Open Other App in iOS 11
How to Make a Phonegap App for iOS Without Mac
iOS Wkwebview Swift JavaScript Enable
Swiftui Xcode 12.3 Can't Change Button Size in Toolbar
How to Print Out(Nslog) The Properties of a Custom Object Added to a Nsmutablearray
How to Reload Data Properly When Retrieving Objects from Parse
Invalid Transaction Receipt Returned by Appstorereceipturl (Nsdata), in iOS 7
Left-To-Right Mark Not Working in Swift
How to Pair And/Or Bond to Ble on iOS Using Swift Code and an Hm-10 So Data Sent Is Encrypted
Googlemap API Gives Wrong Coordinates for Direction Between Two Points
How to Get the Index in Results of a Certain Realm Object
Fix Cursor Size for Modified Paragraph Spacing in Uitextview
Viewdiddisappear Not Called When Use Presentviewcontroller
How to Loop Through and Get All The Keys of The Nested Nodes in Firebase