Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
615 views
in Technique[技术] by (71.8m points)

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

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:

  1. The device gets an APNS token
  2. I then call tokenWithAuthorizedEntity: by using my APNS token
  3. ^ This usually results in one of those two errors mentioned above.
  4. 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:

  1. Is the call to connectWithHandler: in applicationDidBecomeActive: necessary if I am only interested in receiving GCM push messages and not send them upstream?
  2. 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?)
  3. When should the startWithConfig be called? Before getting a GCM token or after?

EDIT: Limited testing revealed that the following appears to work:

  1. Get the GGLInstance ID first (i.e. call getIDWithHandler:)
  2. If the above GGLInstance ID was received without any error, ask for a GCM token (i.e. call tokenWithAuthorizedEntity:)
  3. 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...