IOS GCM error code 501

I recently started getting this error code whenever I try to use the GCM api in my iOS application: Error Domain = com.google.gcm Code = 501 "(null)"

I could not find the meaning of this anywhere? Is this really an HTTP status code, i.e. not implemented?

First I get an error in this line of code:

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

the method call prints this message:

Gcm | GCM registration not ready with auth credentials

and error Error Domain = com.google.gcm Code = 501 "(null)"

+4
source share
2 answers

The error occurred due to the fact that I called

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

before I received the registration token, or could not update the token.

" = com.google.gcm = 501" (null) "" .

+3

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

,

( [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity , ), [[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;
}

, , [[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity: , chcek applicationDidBecomeActive smth.

- (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];

            }

        }];

    }

}

, tokenWithAuthorizedEntity:, , , ,

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

Source: https://habr.com/ru/post/1613388/


All Articles