Hi I've followed the tutorial for using GCM on iOS. It has been working intermittently(which means all the certificates, permissions and stuff is okay). However of late, I have been getting the two error messages repeatedly:
GCM | GCM registration is not ready with auth credentials
.
Also, reconnection to GCM fails with:
Error Domain=com.google.gcm Code=501 "(null)"
This co-relates,in part, to the device not getting a GCM registration ID. Has anyone else come across these issues more frequently of late? Or is it because I'm calling the GCM API in an incorrect sequence (especially the connectWithHandler:
, startWithConfig:
and tokenWithAuthorizedEntity
methods)? I suspect that the reason is the latter since I do get a GCM ID after some delay.
I do not always receive a GCM ID either. When I don't receive one, I usually have to run the app once or twice more via Xcode. (Or by force-closing the app). Clearly this is not something that my users should have to do.
This is the sequence of my GCM API calls:
tokenWithAuthorizedEntity:
by using my APNS token tokenWithAuthorizedEntity
again.Also, I have the connectWithHandler:
call written inside my applicationDidBecomeActive:
method also.
A couple of questions:
connectWithHandler:
in applicationDidBecomeActive:
necessary if I am only interested in receiving GCM push messages and not send them upstream?tokenWithAuthorizedEntity
?)startWithConfig
be called? Before getting a GCM token or after?EDIT: Limited testing revealed that the following appears to work:
getIDWithHandler:
)tokenWithAuthorizedEntity:
)Unable to find token in cache Error Domain=com.google.iid Code=-25300 "(null)"
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. :)
Try move the connectWithHandler block to didFinishLaunchingWithOptions method, after you get the gcmConfig block.(for official's example, after the [END start_gcm_service])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With