CloudKit

RSS for tag

Store structured app and user data in iCloud containers that can be shared by all users of your app using CloudKit.

Posts under CloudKit tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

CKSyncEngine: Can Long-Offline Devices Miss CloudKit Change Notifications?
Problem Description: When a device (Device 2) stays offline for an extended period after a record is deleted from another synced device (Device 1) via CloudKit, is it possible for Device 2 to miss the deletion notification when it reconnects, even when using CKSyncEngine? This scenario raises questions about whether CKSyncEngine can reliably sync changes if CloudKit archives or purges metadata related to deletions during the offline period. Steps to Reproduce: At time t0: · Device 1 and Device 2 sync successfully via CKSyncEngine (shared record RecordA). Device 2 goes offline. On Device 1: · Delete RecordA; sync completes via CKSyncEngine. Wait for a duration potentially exceeding CloudKit’s change retention window (if such a window exists). Bring Device 2 back online. Observe synchronization: · Expected Behavior: CKSyncEngine removes RecordA from Device 2. · Observed Behavior: RecordA remains on Device 2. Key Questions: Under these conditions, can Device 2 permanently miss the deletion event due to CloudKit’s internal metadata management? Is there a documented retention policy for CloudKit’s change history, and how does CKSyncEngine handle scenarios where this history is truncated? What is the recommended pattern to ensure no events are missed, regardless of offline duration? Clarifications Needed: · If CloudKit does discard deletion metadata after a period, is this considered a framework limitation, or should developers implement additional safeguards? · Does CKSyncEngine log warnings or errors when it detects incomplete sync histories? Environment: · CKSyncEngine with SQLite · CloudKit Private Database · iOS/macOS latest versions Thank you for clarifying how CKSyncEngine is designed to handle this edge case!
1
0
64
11h
Request for Guidance on Cross-Platform Heart Rate Data Sharing
Dear Apple Developer Support, I hope this message finds you well. I am reaching out for guidance on a project that involves sharing heart rate data between an iOS app and an Android app. I have developed a watchOS app that continuously fetches heart rate data from an Apple Watch and displays it in a companion iOS app. Additionally, I have built an Android fitness app using Ionic Angular. My goal is to create a bridge that allows the heart rate data from the iOS app to be displayed continuously in the Android app. I am considering using a backend server (e.g., Node.js) to facilitate this data transfer. Could you please provide any insights or recommendations on the best approach for achieving this cross-platform data sharing? I would appreciate any guidance on potential challenges or limitations I might encounter. Thank you for your time and assistance. Sincerely, Venu Madhav
1
0
86
1d
CloudKit Sharing Issue: "Unknown client: ChoreOrganizer"
I'm experiencing a persistent issue with CloudKit sharing in my iOS application. When attempting to present a UICloudSharingController, I receive the error message "Unknown client: ChoreOrganizer" in the console. App Configuration Details: App Name: ChoreOrganizer Bundle ID: com.ProgressByBits.ChoreOrganizer CloudKit Container ID: iCloud.com.ProgressByBits.ChoreOrganizer Core Data Model Name: ChoreOrganizer.xcdatamodeld Core Data Entity: Chore Error Details: The error "Unknown client: ChoreOrganizer" occurs when I present the UICloudSharingController This happens only on the first attempt to share; subsequent attempts during the same app session don't show the error but sharing still doesn't work All my code executes successfully without errors until UICloudSharingController is presented Implementation Details: I'm using NSPersistentCloudKitContainer for Core Data synchronization and UICloudSharingController for sharing. My implementation creates a custom CloudKit zone, saves both a record and a CKShare in that zone, and then presents the sharing controller. Here's the relevant code: @MainActor func presentSharing(from viewController: UIViewController) async throws { // Create CloudKit container let container = CKContainer(identifier: containerIdentifier) let database = container.privateCloudDatabase // Define custom zone ID let zoneID = CKRecordZone.ID(zoneName: "SharedChores", ownerName: CKCurrentUserDefaultName) do { // Check if zone exists, create if necessary do { _ = try await database.recordZone(for: zoneID) } catch { let newZone = CKRecordZone(zoneID: zoneID) _ = try await database.save(newZone) } // Create record in custom zone let recordID = CKRecord.ID(recordName: "SharedChoresRoot", zoneID: zoneID) let rootRecord = CKRecord(recordType: "ChoreRoot", recordID: recordID) rootRecord["name"] = "Shared Chores Root" as CKRecordValue // Create share let share = CKShare(rootRecord: rootRecord) share[CKShare.SystemFieldKey.title] = "Shared Tasks" as CKRecordValue // Save both record and share in same operation let recordsToSave: [CKRecord] = [rootRecord, share] _ = try await database.modifyRecords(saving: recordsToSave, deleting: []) // Present sharing controller let sharingController = UICloudSharingController(share: share, container: container) sharingController.delegate = shareDelegate // Configure popover if let popover = sharingController.popoverPresentationController { popover.sourceView = viewController.view popover.sourceRect = CGRect( x: viewController.view.bounds.midX, y: viewController.view.bounds.midY, width: 1, height: 1 ) popover.permittedArrowDirections = [] } viewController.present(sharingController, animated: true) } catch { throw error } } Steps I've already tried: Verified correct bundle ID and container ID match in all places (code, entitlements file, Developer Portal) Added NSUbiquitousContainers configuration to Info.plist Ensured proper entitlements in the app Created and configured proper provisioning profiles Tried both default zone and custom zone for sharing Various ways of saving the record and share (separate operations, same operation) Cleaned build folder, deleted derived data, reinstalled the app Tried on both simulator and physical device Confirmed CloudKit container exists in CloudKit Dashboard with correct schema Verified iCloud is properly signed in on test devices Console Output: 1. Starting sharing process 2. Created CKContainer with ID: iCloud.com.ProgressByBits.ChoreOrganizer 3. Using zone: SharedChores 4. Checking if zone exists 5. Zone exists 7. Created record with ID: <CKRecordID: 0x3033ebd80; recordName=SharedChoresRoot, zoneID=SharedChores:__defaultOwner__> 8. Created share with ID: <CKRecordID: 0x3033ea920; recordName=Share-C4701F43-7591-4436-BBF4-6FA8AF3DF532, zoneID=SharedChores:__defaultOwner__> 9. About to save record and share 10. Records saved successfully 11. Creating UICloudSharingController 12. About to present UICloudSharingController 13. UICloudSharingController presented Unknown client: ChoreOrganizer Additional Information: When accessing the CloudKit Dashboard, I can see that data is being properly synced to the cloud, indicating that the basic CloudKit integration is working. The issue appears to be specific to the sharing functionality. I would greatly appreciate any insights or solutions to resolve this persistent "Unknown client" error. Thank you for your assistance.
2
0
202
3d
Unable to delete CKShare
Running the Apple sample code “Sharing Core Data objects between iCloud users” has presented the following challenge: After the creation of a CKRecord in a Persistent CloudKit Container private database, the owner then shares it to a participant. All works fine. Then the Owner wants to stop sharing. That's fine too, although the CKRecord remains within the same shared zone within the owner's private database; it doesn't move back to the private database. Then the owner wants to delete the CKRecord completely. Deletion of the record works, but evidence of the CKShare within the shared zone still remains inside the owner's private database. It is clearly visible on the CloudKit dashboard. Probably doesn’t take up much memory but v messy and not cool. How to delete this CKShare completely, leaving no trace? Any ideas would be most gratefully received!
1
0
171
3d
Async Data with iCloud
DESCRIPTION I have an App use iCloud to save data. The App had a CoreData ManagedObject 'Product', 'Product' Object had an attribute name 'count' and it is a Double Type. I need to synchronises 'count' property across multiple devices. for example: I have a devices A、B. A device set 'Product.count' = 100. B device set 'Product.count' = 50. I hope the 'Product.count' == 150 that results. how to synchronises the 'Product.count' == 150 for multiple devices. If I have more devices in future, How to get the latest 'Product.count' that it is correct result.
1
0
236
2d
Records or Fields are Missing or Corrupt in Users Private CloudKit Databases (Recent Changes to CloudKit?)
Hi all, I've contacted Apple about this privately but I wanted to post this publicly too just to see if anyone else is experiencing the same issue. We use CloudKit to store "documents" (we'll call them) for our users. We use it directly, not via CoreData etc but through the lower level APIs. This has been working great for the last 9 months or so. Since a few days ago we've started receiving reports from users that their data has disappeared without a trace from their app. Obviously this is very serious and severe for us. We keep a local copy of the users data but if CloudKit tells us this data has been deleted we remove that local copy to keep in sync. Nothing has changed client side in terms of our code, and the only way we can see that could cause this, is a fetch that we perform asking for a list of the users "documents" is returning no rows/results, or possibly returning rows with invalid or missing fields. We have about 30,000 active users per day (1.5m requests/day) using CloudKit and we have only a handful of reports of this. Again this only started happening this week after 9 months of good service. Has anyone else noticed anything "strange" lately, fetches returning empty? fields missing? Is anyone at Apple aware of any recent changes to CloudKit? or outages? We're really unsure how or who should handle this and who we can escalate to? Any help appreciated. We have a workaround/mitigation on the way through review at the moment but this is a really big problem for us if we can't rely on CloudKit to remember users data reliably.
1
0
264
2d
SwiftData migration error: NSCloudKitMirroringDelegate are not reusable
Hello everyone, I used SwiftData for v1 of an app and am now trying to make changes to the schema for v2. I created the v2 schema that adds a property to one of the models. I need to populate the new property so I made a custom migration using didMigrate. However that doesn't seem to matter what I do in the migration because creating the ModelContainer throws an error before didMigrate ever gets called. The error is: Unresolved error loading container Error Domain=NSCocoaErrorDomain Code=134060 "A Core Data error occurred." UserInfo={NSLocalizedFailureReason=Instances of NSCloudKitMirroringDelegate are not reusable and should have a lifecycle tied to a given instance of NSPersistentStore.} Higher up in the Xcode output I see things like this (in order): Request 'D25A8CB8-7341-4FA8-B2F8-3DE2D35B5273' was cancelled because the store was removed from the coordinator. BUG IN CLIENT OF CLOUDKIT: Registering a handler for a CKScheduler activity identifier that has already been registered CloudKit setup failed because it couldn't register a handler for the export activity. There is another instance of this persistent store actively syncing with CloudKit in this process. How can I know from this output what I am doing incorrectly? Any idea what I should take a look at or try to do differently? This is a simple app with three models and nothing fancy. The only change in the schema is to add a property. The new property is declared as optional and has an inverse that is also declared as optional. Thanks for any insight!
3
0
195
1d
CloudKit CKModifyRecordsOperation resulting in undocumented error "Internal Error" (1/3001); "MMCSEngineCreate failed"
I'm running into an undocumented error coming back from CloudKit operations. Specifically, I'm attempting to save new records via CKModifyRecordsOperation. I'm receiving this error for each of the records in the perRecordSaveBlock callback: &lt;CKError 0x3018ac3c0: "Internal Error" (1/3001); "MMCSEngineCreate failed"&gt; Is anyone else facing this error? It has been happening for several days and I'm finally getting around to reproduction with the Console app and logs. I have 16 records on my device locally that each one gets this error back. FB16547732 - CloudKit: CKModifyRecordsOperation saving new records results in Error &lt;CKError 0x3018ac1e0: "Internal Error" (1/3001); "MMCSEngineCreate failed"&gt;
2
0
287
1d
NSPersistentCloudKitContainer uploads only a subset of records to public database in production environment
I'm having some issues where only a subset of records appear in CloudKit dashboard after I have saved some records in my iOS app using NSPersistentCloudKitContainer. I have noticed that when I'm running my app using the development environment of my CloudKit container everything works smoothly and is uploaded as expected but when I'm using the production environment only a subset of records are actually uploaded. I'm pulling my hair on how to debug this. -com.apple.CoreData.CloudKitDebug and -com.apple.CoreData.SQLDebug pukes out too much info in the console for me to pinpoint any issue.
1
0
388
2w
SwiftData property marked ephemeral getting persisted in CloudKit
Am I misunderstanding the expected behavior here, or is there a bug in the behavior of @Attribute(.ephemeral) tagged SwiftData model properties? The documentation for .ephemeral says "Track changes to this property but do not persist". I started using .ephemeral because @Transient was inhibiting SwiftUI from reacting to changes to the property through @Observable. I am updating the value of my @Attribute(.ephemeral) property about once a second and I am seeing corresponding console log output showing the property as part of the generated CKRecord object. I then confirmed in the CloudKit dev portal that the .ephemeral property was added to the Record schema and contains real values. The behavior seems as though the .ephemeral property is being completely ignored. This is observed in a new Xcode project using SwiftData with CloudKit, Xcode 16.2, macOS 15.3.1 and during Build & Run testing on physical devices.
1
0
372
2w
What is CloudKit error: AssetUploadTokenRetrieveRequest request size exceeds limit
Some of my customer get the following CloudKit error (I cannot reproduce is myself). Failed to modify some records (CKErrorDomain:2) userInfo: CKErrorDescription:Failed to modify some records CKPartialErrors:{ "<CKRecordID: ooo; recordName=ooo, zoneID=ooo:__defaultOwner__>" = "<CKError 0x600003809ce0: \"Limit Exceeded\" (27/2023); server message = \"AssetUploadTokenRetrieveRequest request size exceeds limit\"; op = ooo; uuid = ooo; container ID = \"ooo\">" This is a CKError.limitExeeded error. I create 200 or less records in a batch operation. So I am below the 400 limit. Searching the Internet for "AssetUploadTokenRetrieveRequest request size exceeds limit": 0 results Can anyone give me a hint?
4
0
399
1w
Can't deploy CloudKit schema because of empty record? Why?
When I try to promote schema to production, I get following error: Cannot promote schema with empty type 'workspace', please delete the record type before attempting to migrate the schema again However, in hierarchical root record sharing, I think it should be completely legit use case where there is empty root record (in my case workspace) to which other records reference through ->parent reference. Am I missing something? Is this weird constraint imposed on CloudKit?
1
0
328
2w
Is there a guaranteed order for records in CKSyncEngine's handleFetchedRecordZoneChanges?
I have two recordTypes in CloudKit: Author and Book. The Book records have their parent property set to an Author, enabling hierarchical record sharing (i.e., if an Author record is shared, the participant can see all books associated with that author in their shared database). When syncing with CKSyncEngine, I was expecting handleFetchedRecordZoneChanges to deliver all Author records before their associated Book records. However, unless I’m missing something, the order appears to be random. This randomness forces me to handle two codepaths in my app (opposed to just one) to replicate CloudKit references in my local persistency storage: Book arrives before its Author → I store the Book but defer setting its parent reference until the corresponding Author arrives. Author arrives before its Books → I can immediately set the parent reference when each Book arrives. Is there a way to ensure that Author records always arrive before Book records when syncing with CKSyncEngine? Or is this behavior inherently unordered and I have to implement two codepaths?
1
0
384
3w
CKSyncEngine: Duplicate FetchedRecordZoneChanges & Sync Handling Questions
Hi everyone, I've recently implemented CKSyncEngine in my app, and I have two questions regarding its behavior: Duplicate FetchedRecordZoneChanges After Sending Changes: I’ve noticed that the engine sometimes receives a FetchedRecordZoneChanges event containing modifications and deletions that were just sent by the same device a few moments earlier. This event arrives after the SentRecordZoneChanges event, and both events share the same recordChangeTag, which results in double-handling the record. Is this expected behavior? I’d like to confirm if this is how CKSyncEngine works or if I might be overlooking something. Handling Initial Sync with a "Sync Screen": When a user opens the app for the first time and already has data stored in iCloud, I need to display a "Sync Screen" temporarily to prevent showing partial data or triggering abrupt, rapid UI changes. I’ve found that canceling current operations, then awaiting sendChanges() and fetchChanges() works well to ensure data is fully synced before dismissing the sync screen: displaySyncScreen = true await syncEngine.cancelOperations() try await syncEngine.sendChanges() try await syncEngine.fetchChanges() displaySyncScreen = false However, I’m unsure if canceling operations like this could lead to data loss or other issues. Is this a safe approach, or would you recommend a better strategy for handling this initial sync state?
1
0
341
3w
Developing First Ever IOS App - Have Very Specific Questions to Unblock my Testing
I have developed an app that I had been testing on the hardware device with the developer profile signed builds, I had setup a CloudKit container in development mode and also had tested with Production mode and they are working as expected. I have also tested storekit auto renewal subscriptions using Storekit Config file and all of that is working on the hardware device with the developer profile signed builds. Now comes the Fun Part, I want to use the Distribution profile to test the app for production readiness, I had created a distribution profile and had set that up in the Release under target of the app in Xcode, I have also created sandbox tester account (which is showing inactive even after 7 days - though I am also logged in with this sandbox tester account on a hardware device and under developer setting it shows as a sandbox tester account) All the subscriptions are showing Ready to Submit in the App Store Connect. I need help understand this whole flow, how to ensure I can test CloudKit and storekit for production readiness and then publish my app for the review. Thank you.
0
0
188
3w
CoreData error=134100 Failed to open the store
Hello, I'm using CoreData + CloudKit and I am facing the following error 134100 "The managed object model version used to open the persistent store is incompatible with the one that was used to create the persistent store." All my schema updates are composed of adding optional attributes to existing entities, adding non-optional attributes (with default value) to existing entities or adding new entities Basically, only things that lightweight migrations can handle. Every time I update the schema, I add a new model version of xcdatamodel - who only has a single configuration (the "Default" one). And I also deploy the updated CloudKit schema from the dashboard. It worked up to v3 of my xcdatamodel, but started to crash for a few users at v4 when I added 16 new attributes (in total) to 4 existing entities. Then again at v5 when I added 2 new optional attributes to 1 existing entity. I'm using a singleton and here is the code: private func generateCloudKitContainer() -> NSPersistentCloudKitContainer { let container = NSPersistentCloudKitContainer(name: "MyAppModel") let fileLocation = URL(...) let description = NSPersistentStoreDescription(url: fileLocation) description.shouldMigrateStoreAutomatically = true description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) let options = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.com.company.MyApp") options.databaseScope = .private description.cloudKitContainerOptions = options container.persistentStoreDescriptions = [description] container.viewContext.automaticallyMergesChangesFromParent = true container.loadPersistentStores { description, error in container.viewContext.mergePolicy = NSMergePolicy(merge: .mergeByPropertyObjectTrumpMergePolicyType) if let error { // Error happens here! } } return container } I can't reproduce it yet. I don't really understand what could lead to this error.
4
0
517
3w
How to get a real time and date (not device time) for query?
I need to know the current date to query CloudKit data with it, like: let predicate = NSPredicate(format: "publishedAt <= %@", currentDateAndTime) I don't need high precision, even +/- a few minutes is fine, but I can't rely on device's time since the user can manually change it. Researching this myself I see that the most reliable method is to get the date from the server. There are NTP servers, but accessing them requires additional libraries which adds complexity. TrueTime (last updated 6 years ago) and Kronos (updated like once a year) seem outdated, given how much Swift has changed in the past years. I can make an HTTP request to a website like Google or Apple and read the current time from its headers. But I don't know if this method is reliable. I know I can create a dummy record in CloudKit, update it, and read its modificationDate. But it feels hacky. Maybe there is another way to fetch the current date directly from CloudKit? It feels like it should be easy and there is a straightforward solution, but I just can't find it.
1
0
374
4w
cloudkit
Hello everyone, I'm looking for updated information on CloudKit pricing for both public and private users. Apple provides a free tier, but I couldn't find a clear breakdown of the costs for exceeding the free limits. Specifically, I would like to know: Public data storage: What are the costs associated with storing and querying public records? Private data storage: How is pricing handled when a user's private data exceeds their iCloud quota? Additional requests and bandwidth: Are there any charges for extra API requests or data transfer beyond the free limits? If anyone has insights or an official reference, I'd really appreciate your help. Thanks in advance!
1
0
423
4w