在进行GCM主题消息订阅时,我尝试取消订阅一个主题,但是在我的日志中出现了以下内容(请参见下面的代码)。
Failed to unsubscribe from topic /topics/testTopicName: Error Domain=com.google.gcm Code=7 "The operation couldn’t be completed. (com.google.gcm error 7.)"
现在,我可以使用相同的注册令牌订阅主题,并接收有关此主题的主题消息,但我无法取消订阅。每次尝试取消订阅时,我都会收到此错误信息。根据Google,"7"是一个“未知错误”——太好了...
到目前为止,我已观察到所有我创建的主题都具有相同的行为。
+ (void)unsubscribeFromGCMTopic:(NSString*)topicName
{
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
// If the app has a registration token and is connected to GCM, proceed to unsubscribe from the
// topic
if (app.registrationToken && app.connectedToGCM)
{
NSString* topic = [NSString stringWithFormat:@"%@%@", TOPIC_PREFIX, topicName];
[[GCMPubSub sharedInstance] unsubscribeWithToken:app.registrationToken
topic:topic
options:nil
handler:^void(NSError *error)
{
if (error)
{
NSLog(@"Failed to unsubscribe from topic %@: %@", topic, error);
}
else
{
// Unsubscribe successfully
NSLog(@"Successfully unsubscribe from topic %@", topic);
}
}];
}
else
{
NSLog(@"Cannot GCM unsubscribe from %@. Token %@. GCM connection status %d", topicName, app.registrationToken, app.connectedToGCM);
}
}
有任何想法吗?提前感谢!