For GCM topic messaging, whilst trying to unsubscribe from a topic I'm getting the following in my log (see code below)
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.)"
Now, I'm able to subscribe to the topic with the same registration token, as well as receiving topical messages for this topic, yet I'm not able to unsubscribe from it. I'm getting this every time when trying to unsubscribe. According to Google , "7" is an "unknown error" - great...
I've observed the same behaviour for all the topics I've created so far.
+ (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);
}
}
Any ideas? Thanks in advance!
check in app delegate if using sandbox or production kGGLInstanceIDAPNSServerTypeSandboxOption:true]
for production:
//RECEBE DADOS CERTIFICADOS_APNS_TOKENS
func application( application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken
deviceToken: NSData ) {
let instanceIDConfig = GGLInstanceIDConfig.defaultConfig()
instanceIDConfig.delegate = self
print("\nDEVICE: \(deviceToken)\n")
//PARA TESTAR NOTIFICACAO COLOCAR SANDBOX COMO TRUE e para PRODUCAO COLOCAR COMO FALSE
GGLInstanceID.sharedInstance().startWithConfig(instanceIDConfig)
registrationOptions = [kGGLInstanceIDRegisterAPNSOption:deviceToken, kGGLInstanceIDAPNSServerTypeSandboxOption:false]
GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID, scope: kGGLInstanceIDScopeGCM, options: registrationOptions, handler: registrationHandler)
}
for test using true:
//RECEBE DADOS CERTIFICADOS_APNS_TOKENS
func application( application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken
deviceToken: NSData ) {
let instanceIDConfig = GGLInstanceIDConfig.defaultConfig()
instanceIDConfig.delegate = self
print("\nDEVICE: \(deviceToken)\n")
//PARA TESTAR NOTIFICACAO COLOCAR SANDBOX COMO TRUE e para PRODUCAO COLOCAR COMO FALSE
GGLInstanceID.sharedInstance().startWithConfig(instanceIDConfig)
registrationOptions = [kGGLInstanceIDRegisterAPNSOption:deviceToken, kGGLInstanceIDAPNSServerTypeSandboxOption:true]
GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID, scope: kGGLInstanceIDScopeGCM, options: registrationOptions, handler: registrationHandler)
}
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.