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:
- The device gets an APNS token
- I then call
tokenWithAuthorizedEntity:
by using my APNS token
- ^ This usually
results in one of those two errors mentioned above.
- Whenever I
actually need a GCM token, I force a refetch of the GCM token by
calling
tokenWithAuthorizedEntity
again.
Also, I have the connectWithHandler:
call written inside my applicationDidBecomeActive:
method also.
A couple of questions:
- Is the call to
connectWithHandler:
in applicationDidBecomeActive:
necessary if I am only interested in receiving GCM push messages and not send them upstream?
- 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
?)
- When should the
startWithConfig
be called? Before getting a GCM token or after?
EDIT: Limited testing revealed that the following appears to work:
- Get the GGLInstance ID first (i.e. call
getIDWithHandler:
)
- If the above GGLInstance ID was received without any error, ask for a GCM token (i.e. call
tokenWithAuthorizedEntity:
)
- Doing this generally gives the following error, but at least in a short while(~3-10 seconds), the token is received:
Unable to find token in cache Error Domain=com.google.iid Code=-25300
"(null)"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…