CloudKit watchOS 6 silent notification problem

Hello,


I watch the WWDC video regarding keep iPhone and independent watch app (watchos 6) in sync. So I have made a simple cloudkit subscription on the Apple Watch on a record (watch os 6).


1) On the iPhone I modify the record, but when the iPhone is unlocked the notification is never send from cloudkit to the Apple Watch.


If I modify the record directly on the cloudkit dashboard and

2a) the iPhone is locked, then the silent notification is sent to the watch.

2b) the iPhone is unlocked, then it is show directly on the iPhone. For user visible notification this behavior make sense, but in case of silent notification it doesn´t, because there is no way if you change settings on the iPhone App (iPhone unlocked), that you get a push to the watch (via the cloudkit subscription).


Does anybody have the same problem or any way to get this working with cloudkit?

Replies

In CloudKit a notification based on a subscription is not sent to the one iPhone that posted the change in CloudKit that generates the notification. Therefore it will not be passed from that iPhone to the Apple Watch. If you use any other iPhone to cause the subscription to trigger a notification then it will be sent to that iPhone and passed to the Apple Watch.

I am also trying to get Cloudkit notifications to work, but so far I am not receiving any notifications at all on the watch.


Regarding PBK's reply: In watchOS 6, the Apple Watch is supposed to be a separate independent notification target. In the WWDC presentation they actually explicitly talked about how the Apple Watch will (/should) be notified for a Cloudkit change pushed from the iPhone to the cloud.


But unfortunately it does not seem to work as described for me.

I am using a CKRecordZoneSubscription.

I have some problem and not find solution how to resolve it.

Try to use many different ways. Make separate zone for Watch and Phone, make separate subscription, nothing help. Watch get notification ONLY if Phone is locked.

There is a known bug preventing an independent watch app from receiving CloudKit notifications, which should have been fixed on the latest watchOS beta. May you have a try and post the result?

In case you need to support current and/or earlier versions of watchOS, I received the following workaround through a TSI (tech support incident):


To make CloudKit subscriptions / notifications work on your standalone WatchKit app, the app ID of your WatchKit app target has to be associated with the iCloud container ID. The current Xcode, however, doesn’t allow adding CloudKit capability to a WatchKit app target, and so you don’t have any way to make the association with Xcode.


To work around this issue, you need to make the association manually, and the following steps should help you get to the point.


1. Log in to the developer portal with your developer account and navigate to the App ID list page:

Certificates, Identifiers & Profiles > Identifiers > App ID <developer.apple.com/account/resources/identifiers/list>


2. Tap the app ID of your WatchKit app to navigate to the “Edit your App ID Configuration” page.

The app ID should be something like <your_prefix>.watchkitapp. If you don’t see it, assuming you are using “Automatically manage signing”, which is highly recommended, follow these steps to let Xcode create it:


a. Open your project with Xcode and pick your WatchKit app target.

b. Tap Signing & Capabilities > + Capability and add App Group for the target.

c. Uncheck the “Automatically manage signing” box, then check it back. This forces Xcode to synchronize with the portal.

d. Refresh the App ID list page on the portal to find the app ID.


Note that adding the App Group capability is to let Xcode create the app ID for you; you can remove the capability after seeing the app ID on the portal.


Since you are with Xcode for now, please take this chance to make sure your WatchKit extension has the following capabilities:

a. iCloud > CloudKit, with the right iCloud container picked.

b. Push notifications. Xcode added this for you after you had added CloudKit capability.

c. Background Modes > Remote notification, if you want to support silent notifications.


3. On the “Edit your App ID Configuration” page, check the iCloud box, then click the “Configure” button to show the “iCloud Container Assignment” page, and check the iCloud container you would use on your app, then save the changes.


4. On your testing devices, log out your iCloud account, and then log back in. This is very important because it forces watchOS to re-register the device for remote notification; without this step, watchOS may wrongly use a cached device token, which doesn’t reflect your manual association done above.


You can do this with the following steps:

a. Logging out iCloud on your paired iPhone.

b. Make sure you see no iCloud account shown on your iPhone’s Watch app > General > App ID, and the Settings app on your watch.

c. Log in to iCloud on your paired phone again; make sure the Watch app on your iPhone and Settings app on your watch showing the right status.

d. Restart your iPhone and watch.


5. Test CloudKit subscriptions / notifications with your app.

a. On your Mac, go to “~/Library/MobileDevice/Provisioning Profiles” and remove all the profiles, which forces Xcode to download new ones from the portal.

b. Remember to allow remote notification for your app. You can see that “Allow Notifications” is checked at iPhone Watch app > Notifications > Your app.

c. Make sure WKExtensionDelegate’s didRegisterForRemoteNotifications(withDeviceToken:) is called with a device token every time your app is launched – If you don’t see the method being called, trying restarting Xcode and run again. I did see this method is not called sometimes, in which cases notifications won’t work.

Post not yet marked as solved Up vote reply of ppix Down vote reply of ppix

Thanks for sharing this solution! Ran into same problem, these instructions worked for me. Didn't have to log out of iCloud account though

This worked. Thanks a lot.

I’m still having trouble with CloudKit notifications on watchOS 6.2. I did everything @ppix suggested, which got notifications partly working — my watch app does receive CloudKit remote notifications, but only when it is active. If I push changes to CloudKit while the app is inactive, nothing happens; if I then open the app, the notification is immediately delivered.

I would expect CloudKit notifications to wake my app so it can sync in the background — is that working for anyone?
I take it back, I think they are working… thanks ppix!
I did follow all the steps mentioned by ppix. I do not get the subscription notification in Watch OS. I have done following:
1.Run app in iOS and watchOS(through Xcode, this will help us to check the logs in console)
2.Save some data from the iOS app using CloudKit. Verified that the change appears in my cloudkit dashboard.
3. I do not get the didreciveremotenotification call in the watch.

Appreciate any inputs on fixing this issue.

This is still an ongoing issue with watchOS8. I have successfully subscribed to the public database and the intent is kick off a routine on the watch when a new item is added. The same exact code triggers successfully on my phone but not on the watch. It has been recommended to test directly adding a new item in the CloudKit console, but alas since the changes from WWDC this year my console says I have no containers so I cannot access anything (Apple has been investigating this for weeks now). The sad thing is I can send a silent push from a 3rd party (Firebase) in a similar independent watch app and this is recognized and kicks off the function as intended. This tells me it's not an issue with receiving push notifications, just them being triggered for an independent watch app from CloudKit.

Any help would be greatly appreciated!

  • Any updates on this issue?

    I tried ppx’s workaround many times in the last few days but still can’t get silent push notifications to my watchOS 8 independent app. Like mark49 mentioned, pushes from Firebase to a watchOS app work but CloudKit is not working (at least for me).

    Has anybody verified if Core Data + CloudKit reliably pushes updates to watchOS? How about watchOS using NSPersistentCloudkitContainer?

    I’m verifying that my CKRecordZoneSubscription code works on iOS and then plan to use a TSI to seek help from Apple DTS. I will post what I discover. Thanks.

  • I am also still having this issue after following ppix's workaround. @rokamo did you solve this?

  • Have either of you guys had any luck with this so far? Its pretty sad when a third party system like Firebase Messaging works yet a native implementation does not. Maybe that is what we will have to use (it is free) to build independent watchOS applications of this nature. I just wonder if there any Apple support folks seeing this? The issue is 2 years old now.

Add a Comment

I'm having the same problem on watchOS 8.4.. silent notifications are not being sent to the watch but works perfectly for iOS.

let zoneID = CKRecordZone.ID(zoneName: "Settings", ownerName: CKCurrentUserDefaultName)
let subscriptionID = "settings-subscription-id
let subscription = CKRecordZoneSubscription(zoneID: zoneID, subscriptionID: subscriptionID)
let notificationInfo = CKSubscription.NotificationInfo()
notificationInfo.shouldSendContentAvailable = true
subscription.notificationInfo 
let subscription = try await database.save(subscription)

I call WKExtension.shared().registerForRemoteNotifications() in applicationDidBecomeActive and didRegisterForRemoteNotifications(deviceToken:) does fire. However, didReceiveRemoteNotification does not fire. I also tried some suggestions here like updating the provisioning profile at AppConnect for watch app and extension which makes sense.

Looking at the iCloud console though, the watch is never able to create subscriptions at iCloud at all! I query "Data > Subscriptions" section in console and only see the iOS subscription created. Does each device need to have their own unique subscription? Because I also tried this by putting the vendor device identifier in the subscription ID so each device creates their own, but the watch still never creates a subscription at the server nor does it error on database.save(subscription).

Is there a trick for the watch to create subscriptions at iCloud? I'm using the above code but no errors result from it, but the subscription records never shows up on the iCloud console (but iOS does and receives silent fine). I also have "Supports Running without iOS app" checked if that makes a difference.

  • On which iOS version does it still work for you? For me the background notifications stopped working with iOS 15.3.

  • Also on 15.3 but now can't get it to work again in 15.4. Silent notification seems really flaky overall and unreliable. I've gone down a rabbit hole from posts going back to iOS 11 with the same issue. Maybe I hit some limit with all the testing and just stops until it feels like starting again. Not sure but it's unreliable, inconsistent on iOS it seems, and don't think I've ever seen it work on watch.

  • I take it back.. iOS does work perfectly. Sometimes I have to step away from testing it for a week, then I make changes to the iCloud management portal and the push notification gets sent to iOS using the exact same build.. no code changes. So there is some throttling of some sorts in iCloud, but more likely in iOS because I see them in the Console log but doesn't trigger the didReceive notification event sometimes in those throttled times. However, never have I seen this work for watchOS :(. Maybe it's not meant to if its a companion app to iOS (even though I have it set to "Supports running without iOS installation"). Wondering if anyone tried this with an independent watch app?? At this point, I'm thinking of letting iOS receive the push notification then use WatchConnectivity to tell the watch which maybe the recommended route but just more code and communication flows blah.. First Apple takes away AppGroup sharing with watchOS, then they didn't offer NSUbiquitousKeyValueStore for watchOS, now this.