I am facing very weird problem. when I run this code on iPad
GCMService.sharedInstance().connectWithHandler
({
(error) -> Void in
if error != nil {
loggingPrint("Could not connect to GCM: \(error.localizedDescription)")
} else {
self.connectedToGCM = true
loggingPrint("Connected to GCM")
// [START_EXCLUDE]
self.subscribeToTopic()
// [END_EXCLUDE]
}
})
It works perfect but in iPhone It gives me Could not connect to GCM: The operation couldn't be completed. (com.google.gcm error 501.) PS Both devices have same iOS and this code was working well from past 3-4 months. I dont know what happened now
Based from this documentation , error 501 indicates that there was an internal error in the GCM connection server while trying to process the request, or that the server is temporarily unavailable because of timeouts.
Maybe the error occurred because you are calling GCMService.sharedInstance().connectWithHandler() { error in if(error != nil) { print(error) } }
before you had received a registration token, or had failed to refresh your token.
Try refreshing your registration token. The GGLInstanceIDDelegate
protocol declares an onTokenRefresh
method that is called when the system determines that tokens need to be refreshed.
- (void)onTokenRefresh {
// A rotation of the registration tokens is happening, so the app needs to request a new token.
NSLog(@"The GCM registration token needs to be changed.");
[[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:_gcmSenderID
scope:kGGLInstanceIDScopeGCM
options:_registrationOptions
handler:_registrationHandler];
}
Check this documentation to know how the client app should handle refreshed tokens.
My research came up with plenty possible reasons for 501s. this is why i don't vote the post as duplicate of any of the other 'error 501' questions.
But one answer i have not yet seen is a wrong device clock. Having the wrong time will lead to "com.google.gcm error 501"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.