Whilst all current answers to this question indicate the depreciation of CKModifyBadgeOperation, all of them had advised up until 2022 that it could still be used due to Apple not having a replacement Api. Upon running the following code:
badgeReset.modifyBadgeCompletionBlock = { (error) -> Void in
if error != nil {
print("Error resetting badge: \(error!)")
}
}
CKContainer.default().add(badgeReset)
When run I receive the following error:
Error resetting badge: <CKError 0x3001ddf50: "Invalid Arguments" (12/1017); "CKModifyBadgeOperation is no longer supported">
And from testing following this, the badge count incrementation issue continues, indicating that this has been completely invalidated and cannot be used at all.
Even with UNUserNotificationCenter.current().setBadgeCount(0) this only clears the badge count temporarily.
I'm aware of the proposed "workaround" of creating an extension that manually keeps track of notification count & sets the badge accordingly when a notification is received. However I'm trying to ascertain if as of this current point in time there is now no way whatsoever to clear the badge count on the Cloudkit sever level?
Error resetting badge: <CKError 0x3001ddf50: "Invalid Arguments" (12/1017); "CKModifyBadgeOperation is no longer supported">
This is an intentional change – After having deprecated CKModifyBadgeOperation
seven years ago (2017), we officially torn down the functionality recently. The same situation happened on CKMarkNotificationsReadOperation
and CKFetchNotificationChangesOperation
as well.
There is no drop-in replacement for those APIs.
If you are using CKModifyBadgeOperation
to manage the CloudKit notification badge number, consider writing a push service extension to update the badge number in the push content. How to write a push service extension is discussed in Modifying content in newly delivered notifications.
Your main app and extension can share and maintain the badge number via shared UserDefault
. For more information, see init(suiteName:). For how to configure an app group container, see Configuring App Groups.
If you are still using CKMarkNotificationsReadOperation
and CKFetchNotificationChangesOperation
to track CloudKit database changes, consider using CloudKit subscriptions instead. For a private or shared database, use CKDatabaseSubscription
to get notified of database changes; for a public database, consider using CKQuerySubscription
and your own change token.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.