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

app name in iCloud "Manage Storage" list is wrong
Hello: We have a problem and we don't know how to solve it. We have developed the following two App: app1 and app2 Both App have the function of using iCloud.The iCloud container id of app1 and app2 is the same.We use the document storage function of iCloud. We originally planned to share iCloud data in two app, so we used the same iCloud container, and we released app1 and then app2. Due to the slow progress of app2 development, the related functions of iCloud have not been added to the code yet. But we found a problem. In the storage management of "setup", iCloud, the display name of app1 is app2's name, not app1's name. This causes many of our users to delete the iCloud data of the application by mistake, resulting in losses. Now our question is: What caused the name in app1's iCloud storage management list to be displayed as the name of app2? How should it be solved?
1
0
389
Feb ’24
NSPersistentCloudkItContainer and iCloud synchronization speed issues
In our app, there is a scenario where we write and delete approximately 100MB of files to the iCloud server at once using NSPersistentCloudkItContainer(CoreData). While write, read, and delete operations are immediately reflected in the local database, there is a noticeable delay when accessing the CloudKit Database dashboard. Here is the testing approach we have tried: Data Insert Test
 Prepare around 100MB of data.
 Write the data to CoreData on device A.
 When launching the app on device B, it takes about 5 minutes for the data to be fully synchronized. Data Deletion Test Remove all the added data on device A (immediately reflected in local storage.)
 After performing step 1, leaving device A idle takes about 3 minutes for the deletion to be reflected on device B.
 if the app is deleted on device A after step 1, deletion information does not reach device B. Upon reinstalling the app on device A, the deleted data reappears on device B (synchronized data). The ongoing occurrence of these issues has raised several questions regarding cloud synchronization and synchronization speed: Is the synchronization speed of the Testflight app the same as the one received from the AppStore? Are there traffic limitations per account or device? Despite different perceived speeds for each account or device, is there any factor influencing synchronization speed other than network conditions?
2
0
348
Jan ’24
How to get notified on CKError.quotaExceeded
Hi all, I have an iOS app which uses CloudKit and the standard NSPersistentCloudKitContainer, which I rely on for syncing app data between the user's devices. If the user's iCloud account is full I can see a log message while debugging in Xcode shortly after startup which looks something like this: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _requestAbortedNotInitialized:](2183): <NSCloudKitMirroringDelegate: 0x281ddc1e0> - Never successfully initialized and cannot execute request '<NSCloudKitMirroringExportRequest: 0x2841e00f0> 51383346-87BA-44D8-B527-A0B1EE35A0EF' due to error: <CKError 0x282c50db0: "Partial Failure" (2/1011); "Failed to modify some records"; uuid = 7BA17495-4F05-4AF4-A463-C0DF5A823B2E; container ID = "iCloud.com.neufsters.pangram"; partial errors: { E30B2972-FD4B-4D2A-BD1C-EB6F33F5367D:(com.apple.coredata.cloudkit.zone:__defaultOwner__) = <CKError 0x282c155f0: "Quota Exceeded" (25/2035); server message = "Quota exceeded"; op = FC4D3188D0A46ABC; uuid = 7BA17495-4F05-4AF4-A463-C0DF5A823B2E; Retry after 315.0 seconds> 2FC9A487-D630-444D-B7F4-27A0F3A6B46E:(com.apple.coredata.cloudkit.zone:__defaultOwner__) = <CKError 0x282c52820: "Quota Exceeded" (25/2035); server message = "Quota exceeded"; op = FC4D3188D0A46ABC; uuid = 7BA17495-4F05-4AF4-A463-C0DF5A823B2E; Retry after 315.0 seconds> 903DD6A0-0BD8-46C0-84FB-E89797514D9F:(com.apple.coredata.cloudkit.zone:__defaultOwner__) = <CKError 0x282c513e0: "Quota Exceeded" (25/2035); server message = "Quota exceeded"; op = FC4D3188D0A46ABC; uuid = 7BA17495-4F05-4AF4-A463-C0DF5A823B2E; Retry after 315.0 seconds> }> I would like to know how I can get a callback of some sort so I can run code if this CloudKit/CoreData error happens. In particular I'd like to put up some sort of warning to the user letting them know their data isn't going to sync. Please note that I'm not looking for how to do error handling as a result of a user-initiated CloudKit API call. I'm looking for how to get notified when the background syncing logs errors like the above. Thanks, Russ
3
0
393
2w
SwiftData + CloudKit process for deduplication / consuming relevant store changes?
It is often the case that offline devices can add duplicate entities that needs to be merged when CloudKit syncs. Consider user-created tags. A user might create a Note, and then tag it with a newly created tag “Family.” On a separate offline device, they might create another note, and create another tag also called ”Family.” On device sync, both duplicate ”Family” tags would need to be identified as duplicates based on their name property, merged to a single entity, and their original relationships consolidated to the single merged Tag. And this needs to happen before the CloudKit sync data is presented to the UI in the main context. With Core Data we have the mechanism to consume relevant store changes described here. These tools allow us to listen for remote change, then process them appropriately (e.g. remove / merge duplicates) and then merge the changes into the app’s main context. This perfectly solves the problem described in the first paragraph above. Apple provides code using this mechanism for deduplicating tags in a sample app. Is there a mechanism to solve this deduplication problem using SwiftData technology without implementing and maintaining a parallel Core Data stack?
2
2
660
Feb ’24
CoreData+CloudKit w/ Large Public Database
What is the recommended architecture for a CoreData+CloudKit iOS App that has a large public database? Assume the public database contains 10,000+ Locations from which a User would select a few as favorites. Totally impractical to mirror the locations such that they appear in the App's CoreData having been synced from the .public CloudKit database. Presumably one uses the CloudKit API to query the .public database and display some subset of locations for the User to select? (The selected locations can then be stored in the Users .private (or perhaps .shared) database.) How does one configure CoreData + CloudKit for this scenario? Is there another approach?
2
0
436
Jan ’24
CloudKit push notification not working on Sonoma
I have an app that uses CloudKit push notification (CKDatabaseSubscription) and it's been working all along on Ventura 13.5/Xcode 15.0. But since I upgraded my Mac to Sonoma 14.3/Xcode 15.2, my app no longer receives push notification (didReceiveRemoteNotification is not called) on the Mac. Is this a known issue of either Sonoma or Xcode 15.2? FYI, the same code works perfectly on iOS 17.2.
0
0
305
Jan ’24
CloudKitDaemon [804] Indentity Error
Hello, I build my app on Unity 2021 using the service Unity Cloud Build. I enabled iCloud key-value storage and it correctly show up in the entitlement file. Whenever I try to make a cloud save, Unity Logs says that the process was successful but it didn't save anything on the cloud. I had a look to the logs on my device and I found this strange error: cloudd(CloudKitDaemon)[804] <Error>: Identity set <private> was expected to have a current key set <private>. Error Domain=securityd Code=-25300 UserInfo={NSLocalizedDescription=<private>} cloudd(CloudKitDaemon)[804] <Error>: Identity set <private> does not have a current key set. Not using it. cloudd(CloudKitDaemon)[804] <Error>: Didn't get a service identity from the PCS framework I searched online but I couldn't find anything informative. Any suggestions?
3
0
538
Jan ’24
Using CloudKit JS for a React web app
Hello, everyone! I'm currently working in creating a new web app that will replicate the functionalities of an existing iOS and Mac app. However, since those apps rely on CloudKit to manage all user information, we decided on using CloudKit JS as our backend for our web app. The framework we chose for developing our frontend is React. The question is, since this documentation only mentions the CloudKit JS usage through a CDN (embedded directly in the HTML file) I wanted to ask: is there a "suggested" method for using CloudKit JS in a React project other than importing the CDN in the main html file? in case not, should we use a "traditional" server to access data like they suggest in this thread? All your help will be very much appreciated. Best regards, Eduardo
0
1
495
Jan ’24
How to sync data between iOS and OSX apps with CloudKit?
We have an iOS App developed in SwiftUI that saves data to CloudKit using NSPersistentCloudKitContainer. If I modify any of this data, the changes are synchronized on other iOS devices without problem. We also have an OSX App with StoryBoard using NSPersistentCloudKitContainer to share the same data with iOS devices. Changes made on OSX are updated immediately on iOS devices. But if any data is modified in iOS, it is not updated in the OSX application. Simply by doing Command-Tab twice the OSX app displays the new data. It appears that CloudKit Push Notifications are not causing the OSX application to detect that there are changes to the data and that it needs to be updated. In both cases an NSFetchedResultsController is created and a delegate is placed. The iOS one is called but the OSX one is not. The only difference in the code is that in the iOS app with SwiftUI it is done: var body: some Scene { WindowGroup { InitialTab() .environment(\.managedObjectContext, DataManager.shared.viewContext) } } but this is not done in OSK since NSView does not have the .environmet method. Could this be the problem? What should I do to update data without switching applications on OSX? Any help would be appreciated, Thank you so much.
0
0
229
Jan ’24
CloudKit Sync Complete Event/Notification
How does one know when the CloudKit data in a CoreData+CloudKit (NSPersistentCloudKitContainer) has been fully synchronized. UseCase would be a user starts the App on a second device, user deletes then reinstalls the App, another User accepts a share and the share needs to sync. Is the containerEventChanged Notification for 'import success' the definitive event? CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _finishedRequest:withResult:](3403): Finished request: <NSCloudKitMirroringImportRequest: 0x600002345d10> 729A742A-7F3B-42F1-B04C-72705D41FFEF with result: <NSCloudKitMirroringResult: 0x600000c4edc0> storeIdentifier: 79FA5848-A135-41B1-A36A-09F2F914D23D success: 1 madeChanges: 0 error: (null) As the sync could be time-consuming, is there a way to identify a single CloudKit record?
1
0
651
Jan ’24
'Establishing a User' - CloudKit Discoverability Deprecated.
My App uses Core Data + CloudKit and requires use of CloudKit to store persistent data, that will be shared between Users. I’d like to establish the User’s identity - like so they can augment their Core Data ‘Player’ entity w/ App specific info. Certain interfaces have been deprecated (‘user discoverability’). I’ve taken to creating a ‘dummy shared zone’ and extracting the ‘owner.userIdentity': public func establishUser () async -> User? { let container = cloudKitContainer // If we store the userUUID then the implication is that the `user` can // never be deleted; that is fair enough. let userUUIDKey = "userUUID" var userIdentity = Optional<CKUserIdentity>.none do { // // We'll store the UUID of the CoreData `User` in the CloudKit `User` record. If there // is no UUID in CloudKit, then this will be the first time the User has ever started // the App. We'll create a user and update the CloudKit `User` record // let userID = try await container.userRecordID () let userRecord = try await container.publicCloudDatabase.record (for: userID) // If the `userRecord` does not have a `userUUIDKey` then we must create a new `User`. if nil == userRecord[userUUIDKey] { // See if the user has the required iCloud account. let userStatus = try await container.accountStatus() guard userStatus == .available else { print ("JKP: \(#function) accountStatus: \(userStatus)") return nil } // // Create a `dummyShare` (in a 'dummyZone') so we can access the share's owner // That owner will have our `userIdentity` // do { let dummyZone = CKRecordZone (zoneName: UUID().uuidString) let dummyShare = CKShare (recordZoneID: dummyZone.zoneID) print ("JKP: User: Establish Zone: \(dummyZone.zoneID.zoneName)") // Save the dummyZone and then the dummyShare (for/in the dummyZone) let _ = try await container.privateCloudDatabase.save (dummyZone) let _ = try await container.privateCloudDatabase.save (dummyShare) // Extract the dummyShare's owner's identity - which is 'us/me' userIdentity = dummyShare.owner.userIdentity // Cleanup by deleting the 'dummyShare' and then the 'dummyZone' let _ = try await container.privateCloudDatabase.deleteRecord (withID: dummyShare.recordID) let _ = try await container.privateCloudDatabase.deleteRecordZone (withID: dummyZone.zoneID) } catch { print ("JKP: User Establish Error: \(error.localizedDescription)") } // Create `newUser` with the `userRecordId`. We'll use this to lookup the // Core Data User when players appear in a League. let newUser = User.create (context, scope: Player.Scope.owner, name: (userIdentity?.nameComponents ?? PersistenceController.nameDefault), identification: userIdentity?.lookupInfo .map { PlayerIdentification.create (lookupInfo: $0) } ?? PlayerIdentification()) … } Is this how getting the userIdentity is meant to be done (w/o using the deprecated interfaces)? The deprecated interfaces, when warned in Xcode, reference a sample project; that project doesn’t actually use/get the userIdentity. Also the deleteRecord and deleteRecordZone don’t appear to remove the dummy zone in CloudKit; why?
1
0
367
Jan ’24
isStoredInMemoryOnly has no effect for macOS + iCloud?
Wondering if anyone else is running into this. It seems ModelConfiguration(isStoredInMemoryOnly: true) for previews (as outlined by Paul Hudson / Hacking with Swift) works correctly for iOS + iCloud syncing macOS WITHOUT iCloud syncing But as soon as I turn on iCloud syncing capability for my macOS target, its as if the isStoredInMemoryOnly has no effect on the macOS target. Here's my code... I made a PreviewHelper to encapsulate the preview logic... enum PreviewHelper { static let previewModelContainer: ModelContainer = { do { let config = ModelConfiguration(isStoredInMemoryOnly: true) let container = try ModelContainer(for: Task.self, configurations: config) return container } catch { fatalError("Failed to create model container for previewing: \(error.localizedDescription)") } }() } And then use it like so... #Preview { let container = PreviewHelper.previewModelContainer for task in MockData.tasks { container.mainContext.insert(task) } return HorizonView() .modelContainer(container) } On the macOS target & destination, using a macOS device in the Preview canvas, with iCloud syncing turned on that code inserts the MockData.tasks into my iCloud container every time the preview refreshes, so the data just keeps getting duplicated. With iCloud syncing turned off it behaves as expected/correctly (just inserting the MockData as needed for Previews). In an iOS target, using the same helper and mock data, the helper behaves as expected/correctly (with or without iCloud syncing enabled). Assuming this might be a bug/oversight with SwiftData and macOS? Or am I missing a needed configuration/capability on the macOS side? Anybody else seeing this?
0
1
304
Jan ’24
SwiftUI view not updated after SwiftData change through CloudKit
A SwiftUI view is displaying a SwiftData model object that's being updated on another device, using CloudKit. The update arrives through CloudKit and the view is correctly updated. However, when the view is not displaying the model object directly, but in a nested view, this nested view is NOT updated. Why not? Is this a bug? Or is it just me, forgetting about some elementary detail? A workaround (that I definitely don't like!) is to put a dummy SwiftData query in the nested view. Even when the dummy query result is never used, the view now IS updated correctly. Why? The code below is mostly Xcode's standard template for a SwiftUI+SwiftData+CloudKit app, modified to use a String property i.s.o. a Date, and to be able to edit that name in a Textfield. The ContentView: struct ContentView: View { @Environment(\.modelContext) private var modelContext @Query private var items: [Item] var body: some View { NavigationSplitView { List { ForEach(items) { item in @Bindable var item = item NavigationLink { VStack(alignment: .leading) { // item details in same view TextField(item.name, text: $item.name) .textFieldStyle(.roundedBorder) .padding() .background(.red.opacity(0.5)) // item details in nested view ItemDetailView(item: item) .padding() .background(.yellow.opacity(0.5)) Spacer() } } label: { Text(item.name) } } .onDelete(perform: deleteItems) } #if os(macOS) .navigationSplitViewColumnWidth(min: 180, ideal: 200) #endif .toolbar { #if os(iOS) ToolbarItem(placement: .navigationBarTrailing) { EditButton() } #endif ToolbarItem { Button(action: addItem) { Label("Add Item", systemImage: "plus") } } } } detail: { Text("Select an item") } } private func addItem() { withAnimation { let newItem = Item(name: "item") modelContext.insert(newItem) } } private func deleteItems(offsets: IndexSet) { withAnimation { for index in offsets { modelContext.delete(items[index]) } } } } The nested ItemDetailView: struct ItemDetailView: View { @Bindable var item: Item // dummy query to force view updates triggered by CloudKit // @Query private var items: [Item] var body: some View { TextField(item.name, text: $item.name) .textFieldStyle(.roundedBorder) } } The result:
1
0
469
Jan ’24
CKQueryOperation in private database produces 500 errors from server and in CloudKit Console
I've been scratching my head on this one. Out of the blue, part of my 'synchronization' mechanism that copies 'favorites' from device to device has stopped working. A user can save a favorite location and it will propagate to all of their other devices, or repopulate after an uninstall and reinstall. My code in the space hasn't changed for months and I haven't made any schema changes to this type either. Last night I noticed the process wasn't working anymore. My CKQueryOperation result completion is returning this error: &lt;CKError 0x2818a16b0: "Server Rejected Request" (15/2001); "Request failed with http status code 500"; uuid = 2CA523A6-8F39-4538-98AF-E9B7D6CACF73&gt; What is telling to me is that the CloudKit Console also fails with an internal error when I try to query this type in MY private database for two different accounts. I can query another type in the private database but this one won't work for two of the Apple ID's I have tried. Also interesting, if I query this type in the PUBLIC database, even though this type is only saved to the private database, that operation succeeds just fine. I don't want to burn a DTS ticket for a server issue. FB13543186 - CloudKit: Receiving 500 when performing a query operation on the private database CloudKit status page is green on the developer site as of this morning.
3
0
576
Apr ’24
Delay in CKRecord uploads
Hi, I have recently noticed that it's taking my app a long time between the CKModifyOperations being 'completed' in the app, and for the record to actual show up through either looking at the CloudKit dashboard, or by using CKQueryOperations. The whole upload can take 10-15 minutes or more, from the time the CKOperation has completed to the time I can see all the records on the dashboard. The 'upload' seems to be happening in chunks ... for e.g. if I uploaded a 100 records, if I check after 2 minutes the query will show 20 records, and then 35-40 a bit later, and after 10+ minutes will show all 100 records (exact numbers vary of course). This was never an issue before, but has recently been reported by a couple of users of my app, and I need to know what's going on before it balloons into a big thing. And it's highly problematic, because it leads to users not being able to download the records that they uploaded on the first device. Is there something in CloudKit servers that have changed recently? Can someone in the CloudKit team take a look? I filed a Feedback, along with CloudKit profile logs: FB13537245 I can also reproduce the issue in production as well as development environments.
1
0
320
Jan ’24
SwiftData with CloudKit failing to migrate schema
My app has been in the App Store a few months. In that time I've added a few updates to my SwiftData schema using a MigrationPlan, and things were seemingly going ok. But then I decided to add CloudKit syncing. I needed to modify my models to be compatible. So, I added another migration stage for it, changed the properties as needed (making things optional or adding default values, etc.). In my tests, everything seemed to work smoothly updating from the previous version to the new version with CloudKit. So I released it to my users. But, that's when I started to see the crashes and error reports come in. I think I've narrowed it down to when users update from older versions of the app. I was finally able to reproduce this on my end, and Core Data is throwing an error when loading the ModelContainer saying "CloudKit integration requires that all attributes be optional, or have a default value set." Even though I did this in the latest schema. It’s like it’s trying to load CloudKit before performing the schema migration, and since it can’t, it just fails and won’t load anything. I’m kinda at a loss how to recover from this for these users other than tell them to delete their app and restart, but obviously they’ll lose their data that way. The only other idea I have is to setup some older builds on TestFlight and direct them to update to those first, then update to the newest production version and hope that solves it. Any other ideas? And what can I do to prevent this for future users who maybe reinstall the app from an older version too? There's nothing special about my code for loading the ModelContainer. Just a basic: let container = try ModelContainer( for: Foo.self, Bar.self, migrationPlan: SchemaMigration.self, configurations: ModelConfiguration(cloudKitDatabase: .automatic) )
4
3
1.1k
Mar ’24
TooManyProviderTokensUpdates - how many is too many
Our service is 100% on token-based authentication with APNs. Each pod generates a new token to use every 30 mins. We have hundreds of pods. We implemented this way because in Refresh your token regularly section it says Refresh your token no more than once every 20 minutes and no less than once every 60 minutes. APNs report an error if you use a new token more than once every 20 minutes on the same connection. However, we saw TooManyProviderTokensUpdates sporadically. What is even stranger is, the trigger of the error does not correlate to the number of pods as we scaled up or down, nor does it correlate to the QPS. To me, it looks like It triggers randomly. Can someone from Apple shed some light on this?
0
1
228
Jan ’24
SwiftData + iCloudkit sync Error
In my Swiftui - SwiftData based Application I get the following error after running it both on simulator and real device... The App itself runs, and all Cloudkit requirements are met on data model side. So the problem is, that it is simply no syncing to iCloud: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(): <NSCloudKitMirroringDelegate: 0x282648620>: Failed to set up CloudKit integration for store: <NSSQLCore: 0x10440b270> (URL: file:///var/mobile/Containers/Data/Application/731332F0-B79C-4433-AF57-875C3CC72FCD/Library/Application%20Support/default.store) <CKError 0x28112d860: "Partial Failure" (2/1011); "Failed to modify some record zones"; uuid = 98551939-72A4-4EBB-BB0E-6E6D87DCE285; partial errors: { com.apple.coredata.cloudkit.zone:defaultOwner = <CKError 0x281112070: "Server Rejected Request" (15/2001); "Request failed with http status code 500"; uuid = 98551939-72A4-4EBB-BB0E-6E6D87DCE285> }> error: CoreData+CloudKit: recoverFromError:](): - Attempting recovery from error: <CKError 0x28112d860: "Partial Failure" (2/1011); "Failed to modify some record zones"; uuid = 98551939-72A4-4EBB-BB0E-6E6D87DCE285; partial errors: { com.apple.coredata.cloudkit.zone:defaultOwner = <CKError 0x281112070: "Server Rejected Request" (15/2001); "Request failed with http status code 500"; uuid = 98551939-72A4-4EBB-BB0E-6E6D87DCE285> }> error: CoreData+CloudKit: _recoverFromError:withZoneIDs:forStore:inMonitor:](): <NSCloudKitMirroringDelegate: 0x282648620> - Failed to recover from error: CKErrorDomain:15 Recovery encountered the following error: (null):0 Can anyone help me with this Problem Thank you! Kind Regards Chris
2
0
769
Jan ’24