CKModifyBadgeOperation is no longer working?

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?

Answered by DTS Engineer in 800647022

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.

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.

Hi, so to confirm if using subscriptions for notifications on cloudkit, i would have to manually alter the badge number shown?

Yes, if your subscriptions use visible notifications with a badge, you need to maintain badge number.

This really seems like an oversight, why would cloudkit continue to keep track of the badge number but then not allow me to reset it? I would much rather cloudkit didnt keep track of the badge count if its not going to allow me to clear it?

My understanding is that CloudKit and APNs are two different systems, and the badge number is probably needed for the integration of the systems. However, tracking the notification history adds some (probably too much) complexity to the CloudKit framework, and folks eventually decided to let apps do the tracking, if they need.

With your own push service extension, you can clear the badge number in the notification payload; on the app side, you can use setBadgeCount(_:withCompletionHandler:) to update the badge count. I agree that is a burden on your side, but hopefully is also a reasonable solution.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Following up on this as different behaviour now appears to be taking place after NO changes at all on my end. Push notifications now only ever badge with 1, regardless of how many have come through.

If/when I clear the badge, the next time a notification comes through, it is 1.

Apple, please advise if this was an intended change (band-aid) on this issue?

CKModifyBadgeOperation is no longer working?
 
 
Q