I'm testing with three iDevices. Device 1 fires CKSubscription change notification.
Device 2 and 3 receives the notification and the badge number increases to 1.
I coded to reset the badge number to 0 everytime app comes to foreground like below.(in applicationDidBecomeActive:)
CKModifyBadgeOperation *badgeResetOperation = [[CKModifyBadgeOperation alloc] initWithBadgeValue:0];
[badgeResetOperation setModifyBadgeCompletionBlock:^(NSError * operationError) {
if (!operationError) {
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
}];
[[CKContainer defaultContainer] addOperation:badgeResetOperation];
If user taps my app on device 2, above code will be executed. It works well. The badge number is reset to 0. But the issue is that badge number on device 3 also become 0 simultaneously, even though I didn't tap my app on device 3.
I hope that device 3 remains with increased badge number since user didn't tap it.
API Reference says 'This operation object can update the badge for the current device or for all of the user’s devices.'
https://developer.apple.com/reference/cloudkit/ckmodifybadgeoperation?language=objc
I believe it means that there's a way to reset only a single device I want.
Please anybody guide me how to accomplish it.
If all your 3 devices are logged in with the same iCloud ID they will all share the same badge count. The badges are stored onto the user's iCloud account. That is why it is the same across every device logged with that account.
Log your other devices on different iCloud accounts and run your test again. That should work.
Also, when saving your subscriptions make sure you are saving the same multiple times otherwise you will get multiple badges for the same notification. Check the existence of a subscription before saving it again.