CoreData with CloudKit on watchOS

Hello,


I have managed to get CoreData with CloudKit working with the new NSPersistentCloudKitContainer on the iOS version of my app and got it to automatically sync while the app is running. However, when I went to set things up on the watchOS app, I noticed that a sync will only occur if I force close and reopen the watch app.


The following scenarios work

  • User has both the watchOS app and iOS app running
  • User makes a change to the data on the watch app
  • The change is reflected on the iOS app


  • User has only the iOS app running
  • User makes a change to the data on the iOS app
  • The user opens the watchOS app from terminated
  • The changes are reflected on the watchOS app


The following scenario does not work

  • User has the watchOS app running and the iOS app running
  • User makes a change to the data on the iOS app
  • No change every makes it through to the watchOS app, even after waiting a long time
  • Only if I force close the app and restart does a sync occur


In the cases were a sync is successful I see the following logs correctly:

CoreData: debug: CoreData+CloudKit: -[PFCloudKitImporterZoneChangedWorkItem newMirroringResultByApplyingAccumulatedChanges:]_block_invoke_2(243): <PFCloudKitImporterZoneChangedWorkItem: 0x16530fb0> {

(

"<CKRecordZoneID: 0x1656a920; zoneName=com.apple.coredata.cloudkit.zone, ownerName=__defaultOwner__>"

)

} - Importing updated records:

(

"<CKRecord: 0x16526280; recordType=CD_LogEntry, values={\n \"CD_day\" = 15;\n \"CD_entityName\" = LogEntry;\n \"CD_glassesGoal\" = 8;\n \"CD_glassesLogged\" = 13;\n \"CD_lastModified\" = \"2019-09-15 18:56:08 +0000\";\n \"CD_month\" = 9;\n \"CD_year\" = 2019;\n}, recordChangeTag=7d, recordID=2180D6A3-ACFC-4421-8CAF-6EE288DAAC2E:(com.apple.coredata.cloudkit.zone:__defaultOwner__)>"

)

Deleted RecordIDs:

{


}


In the last scenario, however, I don't see any logs, it's completely quiet. I am sharing the same CoreData/CloudKit code in both the iOS and watchOS versions of the app. I am also using a NSFetchedResultsController<LogEntry> to make sure my UI stays up to date and it seems to be working on the iOS app but not the watchOS app. Not sure if there was some step that I had missed when setting up the watch extension.


Any help would be appreciated.

  • I'm experiencing this right now. Has anyone solved it?

  • Never mind. It's somehow working now :)

Add a Comment

Replies

Same here. Export works, single initial import on launch works but scheduled or trigerred or otherwise automated not. Remote notification for subscription isn't even received on watch. Automated import on events like app state doesn't work. Not even after one hour of running. watchOS 6.0.1.