在iOS上获得GCM推送通知的注册令牌的正确顺序? GCM不可靠吗? [英] Proper sequence to get registration token for GCM push notification on iOS? Is GCM unreliable?

查看:955
本文介绍了在iOS上获得GCM推送通知的注册令牌的正确顺序? GCM不可靠吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我按照在iOS上使用GCM的教程。它一直工作间歇(这意味着所有的证书,权限和东西是好的)。但是,最近,我一直得到两个错误消息:



GCM | GCM注册尚未准备好验证凭据



此外,重新连接到GCM失败:



错误域= com.google.gcm代码= 501(null)



- 部分与设备未获取GCM注册ID相关。有没有人更经常遇到这些问题的最晚?或者是因为我以不正确的顺序调用GCM API(特别是 connectWithHandler: startWithConfig: tokenWithAuthorizedEntity 方法)?我怀疑原因是后者,因为我获得GCM ID一段延迟后。



我也不会总是收到GCM ID。当我没有收到一个,我通常需要运行应用程序一次或两次通过Xcode。 (或通过强制关闭应用程序)。显然,这不是我的用户应该做的。



这是我的GCM API调用的顺序:


  1. APNS令牌

  2. 然后通过使用我的APNS令牌调用
    tokenWithAuthorizedEntity: li> ^这通常
    导致上述两个错误之一。

  3. 每当I
    实际需要一个GCM令牌时,我强制重新获取GCM令牌
    再次呼叫 tokenWithAuthorizedEntity

connectWithHandler:调用写在我的 applicationDidBecomeActive:方法中。



几个问题:


  1. 调用 connectWithHandler: code>在 applicationDidBecomeActive:如果我只想接收GCM推送消息,并且不是向上游发送?
  2. b $ b
  3. 如果对(1)的回答是肯定的,那么在该方法的完成处理程序中,如果发生错误,并且我没有GCM令牌,那么我应该尝试再次获取令牌吗? (即调用 tokenWithAuthorizedEntity ?)

  4. 应调用 startWithConfig 获取GCM令牌之前或之后?

EDIT:有限测试显示以下内容似乎有效:


  1. 先获取GGLInstance ID(即调用 getIDWithHandler:

  2. 如果收到上述GGLInstance ID没有任何错误,请询问GCM令牌(即调用 tokenWithAuthorizedEntity:

  3. 这样做通常会产生以下错误,但至少在短时间内(约3-10秒),会收到




无法在高速缓存中找到令牌错误域= com.google.iid代码= -25300
(null)



解决方案


是connectWithHandler的调用:applicationDidBecomeActive:
必要if我只想接收GCM推送消息,而
不会将其发送到上游?


是, connectWithHandler ,因为其主要目的是与GCM端点建立连接。


如果回答(1)为yes,那么在该方法的完成处理程序中,如果
发生错误,没有GCM令牌在那一点,应该
我试图再次获得一个令牌? (即调用tokenWithAuthorizedEntity?)


所以它应该工作的方式是检查错误,当你请求令牌本身,并重试如果请求失败,则指数退避。更多信息此处。此外,请阅读此处的注释。现在,如果您仍然想要重新调用 GGLInstanceIDTokenHandler ,您在任何时候都应该实现 deleteTokenWithAuthorizedEntity 令牌。


startWithConfig应何时调用?获取GCM令牌
或之后?


在您的 AppDelegate.m 中,您应该调用 GGLInstanceID 共享实例使用 startWithConfig 方法。基本上在 GGLINstanceID.h 类中,它应该首先获取实例ID;然后将该项目授权为授权实体,然后通过iid服务获取注册令牌。查看 GGLInstanceID.h 的详细实施这里



希望此回答有帮助!



EDIT b

此< a>回答你的问题?它的要点是,确保您的目标的Bundle标识符与info.plist文件中的BUNDLE_ID相同。



希望这可以解决错误,如果不发布测试时发生的事情,我们可以从那里。 :)


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)"

解决方案

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上获得GCM推送通知的注册令牌的正确顺序? GCM不可靠吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆