我面临着非常奇怪的问题。当我在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]
}
})
它完美但在iPhone中它让我无法连接到GCM:操作无法完成。 (com.google.gcm错误501.) P.S两种设备都具有相同的iOS,并且此代码在过去3-4个月内运行良好。我不知道现在发生了什么
答案 0 :(得分:0)
根据此documentation,错误501表示尝试处理请求时GCM连接服务器中存在内部错误,或者服务器因超时而暂时不可用。
可能是因为您在收到注册令牌之前调用GCMService.sharedInstance().connectWithHandler() { error in if(error != nil) { print(error) } }
或者无法刷新令牌而发生错误。
尝试刷新您的注册令牌。 GGLInstanceIDDelegate
协议声明了一个onTokenRefresh
方法,当系统确定需要刷新令牌时调用该方法。
- (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];
}
检查此documentation以了解客户端应用应如何处理刷新的令牌。
答案 1 :(得分:-1)
我的研究提出了很多可能的原因501s。这就是为什么我不将该帖子作为任何其他“错误501”问题的重复投票。
但我还没有看到一个答案是错误的设备时钟。错误的时间将导致“com.google.gcm错误501”