简体   繁体   English

iOS GCM错误代码501

[英]iOS GCM error code 501

Recently I start to get this error code whenever I try to use the GCM apis in my iOS app: Error Domain=com.google.gcm Code=501 "(null)" 最近,当我尝试在我的iOS应用程序中使用GCM apis时,我开始收到此错误代码:Error Domain = com.google.gcm Code = 501“(null)”

I couldn't find the meaning of this anywhere? 我无法在任何地方找到这个意义吗? Is that actually the HTTP-status code, meaning Not Implemented? 这实际上是HTTP状态代码,意味着没有实现?

I'm getting the error first at this line of code: 我在这行代码中首先得到错误:

        GCMService.sharedInstance().connectWithHandler() { error in  if(error != nil) {   print(error) } }

calling the method prints this message : 调用该方法打印此消息:

GCM | GCM | GCM registration is not ready with auth credentials GCM注册尚未准备好使用身份验证凭据

and the error is Error Domain=com.google.gcm Code=501 "(null)" 错误是错误域= com.google.gcm代码= 501“(null)”

The error occurred because I was calling 发生错误是因为我正在打电话

GCMService.sharedInstance().connectWithHandler() { error in  if(error != nil) {   print(error) } } 

before I had received a registration token, or had failed to refresh my token. 在我收到注册令牌或未能刷新令牌之前。

"Error Domain=com.google.gcm Code=501 "(null)" " is a really bad error message. “Error Domain = com.google.gcm Code = 501”(null)“”是一个非常糟糕的错误消息。

if you are been developing using this sample 如果你一直在使用这个样本开发

https://github.com/googlesamples/google-services/blob/master/ios/gcm/GcmExample/ https://github.com/googlesamples/google-services/blob/master/ios/gcm/GcmExample/

than you have to know, it is quite poor and wrong in some points 比你必须知道的,在某些方面它是非常糟糕和错误的

to fix the error above (you did request the [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity successfully, but still that error pops up), you have to call ALSO [[GGLInstanceID sharedInstance] startWithConfig: before calling the [[GCMService sharedInstance] connectWithHandler: 修复上面的错误(你确实成功请求[[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity ,但仍然弹出错误),你必须调用ALSO [[GGLInstanceID sharedInstance] startWithConfig:在调用[[GCMService sharedInstance] connectWithHandler:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    NSError* configureError;
    [[GGLContext sharedInstance] configureWithError:&configureError];

    if (configureError) {
        NSLog(@"Error configuring Google services: %@", configureError);
    }

    GCMConfig *gcmConfig = [GCMConfig defaultConfig];
    gcmConfig.receiverDelegate = self;
    [[GCMService sharedInstance] startWithConfig:gcmConfig];

    // add this
    {
        GGLInstanceIDConfig *instanceIDConfig = [GGLInstanceIDConfig defaultConfig];
        instanceIDConfig.delegate = self;

        [[GGLInstanceID sharedInstance] startWithConfig:instanceIDConfig];
    }

    ...
    [self requestAndSynchronizeGCMTokenIfNeeded];
    ...

    return YES;
}

BUT remember, you will always get the error, when the [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity: did not complete, so you should add a chcek for that in the applicationDidBecomeActive smth. 但请记住,当[[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:未完成时,您将始终收到错误,因此您应该在applicationDidBecomeActive smth中添加一个chcek。 like 喜欢

- (void)applicationDidBecomeActive:(UIApplication *)application {

    if (self.data.deviceToken) {

        [[GCMService sharedInstance] connectWithHandler:^(NSError *error) {

            if (error) {

                NSLog(@"Could not connect to GCM: %@", error.localizedDescription);

            } else {

                self.connectedToGCM = YES;
                NSLog(@"Connected to GCM");

                [self subscribeToTopic];

            }

        }];

    }

}

and the last thing, you should try to connect in the handler block of tokenWithAuthorizedEntity: as it is sometimes called before the token is recaived and therefore ending in error 最后一件事,你应该尝试连接tokenWithAuthorizedEntity:的处理程序块tokenWithAuthorizedEntity:因为它有时在令牌被重新接收之前被调用,因此以错误结束

[[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:gcmSenderID scope:kGGLInstanceIDScopeGCM options:options handler:^(NSString *token, NSError *error) {
  // connect to GCM also here ([[GCMService sharedInstance] connectWithHandler:)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM