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

SwiftData project segfaults when I enabled iCloud sync
The crash is at do { retval = try ModelContainer(for: schema, configurations: [modelConfiguration]) } catch { fatalError("Could not create ModelContainer: \(error)") } When I first set it up, it complained (at run-time) about a lot of issues, mainly items not being optional and I apparently had a couple of @Attribute(.unique)s left. After I got rid of all of those, however, I get the crash there. I assume this is an obvious thing that I am doing wrong, but I can't figure it out.
3
0
510
Nov ’23
In CloudKit, how do I check whether the user of an app is the share-sender or the share-receiver?
In other words, I’m trying to setup sharing in my app using Core Data with CloudKit. Basically the user can share their list of CloudKit records with other users of the app. Should that other user accept that share from that share-sender, the share-receiver can then sees the sender’s list of records. This part works as I need it to. This is fine. As well, the app is largely being written in SwiftUI. However, what I also need is to give the user the ability to see only their own records, or to set one of their records to private. I think I can figure this logic out, but I’m still not sure of how to filter the sender versus receiver of that share, AKA owner vs participant. I’ve tried several things to figure this out, and I keep coming up empty. I feel like there’s a good way to do this, however what I’ve done always has issues. Can someone please describe the best way to do this?
0
0
390
Oct ’23
Receiving NSPersistentStoreRemoteChange notification when app is closed
I use NSPersistentCloudKitContainer to fetch/sync data across multiple devices with the same iCloud account. /// ... container = NSPersistentCloudKitContainer(name: containerName) let description = container.persistentStoreDescriptions.first description?.setOption( true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) description?.setOption( true as NSNumber, forKey: NSPersistentHistoryTrackingKey) let viewContext = container.viewContext viewContext.automaticallyMergesChangesFromParent = true viewContext.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump NotificationCenter.default.addObserver( forName: .NSPersistentStoreRemoteChange, object: container.persistentStoreCoordinator, queue: .main ) { _ in Task { @MainActor [weak self] in // fetch new data and update widgets with it // ... viewContext.fetch ... // WidgetCenter.shared.reloadAllTimelines() } } } /// ... Everything works fine when my app in the foreground. How can I achieve the same when my app is closed/ in the background? I know that CloudKit can send silent push notification which can wake up my app but I've never seen the implementation of it using CoreData NSPersistentCloudKitContainer
0
0
413
Oct ’23
Swiftdata: CloudKit integration requires that all attributes be optional, or have a default value set
Unfortunately I can not get swiftdata to work for me. I created a brand new project in Xcode, modified no code and the program fails with this error. Only thing I did was add an iCloud container. The default code that you are given for a swiftadata object is: @Model final class Item { var timestamp: Date init(timestamp: Date) { self.timestamp = timestamp } } Xcode wants that values in this model to ether be optional or have a default value. I thought this was a bug that had been fixed, but I am on the latest Xcode. I am not sure how to proceed. If the default code Xcode gives you won't compile, how am I able to code my own?
1
0
505
Oct ’23
CloudKit subscription only works when operation is performed in CloudKit Dashboard and not when done programmatically
I have set up a CKQuerySubscription in the default zone that sends a Push notification every time a record meeting the given criteria is deleted in a public CloudKit database. However, the notification is only sent when I delete the record via the CloudKit Dashboard and not when I delete a record programmatically. I have tried creating a record with User A on a device and then having that record deleted by User B on a different device but it doesn't result in User A getting notified. Additionally, the only case where the notification gets sent is on a device that is signed in with the iCloud account that I use for CloudKit Console. In other words, when I delete a record that was created by a user with a different iCloud account than the one I use for the CloudKit Console the notification does not get sent to that device - it's only successful on the device with the CloudKit Console iCloud account. What I expect to happen is the subscription to fire when the record in question is deleted regardless of how and by whom it is deleted. Is this possible? Any help would be appreciated.
1
1
495
Oct ’23
CloudKit stopped syncing on WatchOS
Hey, I have an iOS/watchOS application that has been in the App Store since the beginning of last year (for reference: https://endsplus.com). Part of the functionality includes: Create a Fixture on the Phone Create Fixture on iOs Fixture is saved to Core Data Core Data syncs with CloudKit WatchOs pulls down the record, updating a table of the same name I can show the Fixtures on the Watch. Track a game on the Watch and then save it. Create a Game on WatchOS Game is saved to Core Data Core Data syncs with CloudKit iOS pulls down the record, updating a table of the same name I can show the games on the phone. For reasons I am unable to work out syncing of core data tables between the phone and the watch has stopped working. I know that the iOS coredata/cloudkit functionality is working as I can create a record on my physical phone, then run a simulator and log in with the same iCloud account and see the record. But the functionality has stopped working for watchOS. I have added a new table to the Watch side that is not syncing to the Phone, but an existing table (Fixture) that has been working has also stopped syncing between the phone and the watch. None of my Persistence/Core Data code has changed. My new table is associated with a Cloud Store, the same as my old table is. What options are they available to me to try and debug this. The watchOs simulator doesn't seem to work with CloudKit, telling me it is not signed in. I've tried looking at the CloudKit database logs, but obviously for security I can't see the data, but I can't see any errors from the watch. I've uninstalled and re-installed the application (on the phone and the watch) numerous times, but that isn't working. Does anyone have any ideas? Thanks
4
0
615
Oct ’23
Cloudkit discrepancy between tvOS and iOS
Hi, I have an application that would require sync between iOS and tvOS devices. The cloudkit saving/loading code is exactly the same for both platforms but the data does not seems to be synchronised between the 2 devices. Even when I tried to output the data that was updated, iOS only show the data: CKRecord: 0x123456789> whereas tvOS showed more details like: CKRecord: 0x987654321; recordType=SavedGame, recordID=save_file.dat:(_defaultZone:__defaultOwner__), recordChangeTag=ln2rxsh8, values={ data = "<CKAsset: ??; referenceSignature={length = 21, bytes = 0x??????}, path=~/Library/Caches/save_file.dat, size=8005, UUID=?????, signature={length = 21, bytes = 0x?????????}, wrappedAssetKey=<24 bytes>>"; *I replaced the actual data information with ???? Although both have the exact same uploading code, I am having difficulty synchronising between both devices. Not sure what other settings did I missed out to ensure that both can be synchronised properly. Both are using the same iCloud account and apple account. Would appreciate any help. Thank you.
0
0
336
Oct ’23
How to fix NSCloudKitMirroringDelegate unhandled exception after faulty model change
I have a complex data model in development mode, with a large amount of data, using CoreData with CloudKit sync. All worked fine, syncing from a Mac to an iPad Pro, until I made some unwise changes to the model and a couple of relationships. I should have known, but was hurrying and not thinking clearly. The App is not on the App Store: it's for my own use. Records are now not synced to CloudKit: _error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _importFinishedWithResult:importer:]- (1371): <PFCloudKitImporter: 0x6000005d8080>: Import failed with error: Error Domain=NSCocoaErrorDomain Code=134421 "Import failed because applying the accumulated changes hit an unhandled exception." UserInfo={NSLocalizedFailureReason=Import failed because applying the accumulated changes hit an unhandled exception., NSUnderlyingException=* -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]}_** It seems that there's a queue of faulty (non-matching) updates, which I can find no way of purging. Perhaps I could disconnect the CloudKit syncing in the app, use the CloudKit console to reset the development environment, then reconnect CloudKit syncing in the app - but would that invoke a repopulation of the CloudKit data, or cause a deletion of all CoreData data? I can, with a few days' work, reimport all of the data - but that would, I assume, need a newly named app so as to create a new CloudKit container. Any thoughts/solutions would be appreciated. Regards, Michaela
4
0
700
Oct ’23
shouldSendContentAvailable on macOS
I want my Mac app to receive silent push notifications from a CKSubscription while the app is not running. Is that possible? Does the following apply to macOS apps too, or only to iOS apps? That flag causes the system to wake or launch an app that isn’t currently running. The app then receives background execution time to download any data for the push notification, such as the set of changed records. https://developer.apple.com/documentation/cloudkit/cksubscription/notificationinfo/1515110-shouldsendcontentavailable
0
0
341
Sep ’23
CloudKit causes SwiftUI Menu to be dismissed
After updating to iOS 17 and Xcode 15 I noticed that menus on my app get automatically dismissed while CloudKit is syncing data right after opening the app. I know it's CloudKit because this issue doesn't happen when I launch the app in Airplane Mode. It looks like CloudKit causes something to change (even when there are no data changes since the last usage), which causes the UI to refresh. This refresh causes the menus to be dismissed. This is frustrating because users have to tap a button two or three times before being able to interact with the menu showed by the button. I'm attaching a screen recording that shows the issue: https://youtube.com/shorts/Wl9gP2HLktE I open the app and tap the "+" icon, which shows the menu. The menu is quickly dismissed. I tap the "+" icon again, and the menu is shown for a millisecond, and is dismissed again. I tap the "+" button once again. This time the menu is shown and stays there because CloudKit has finished its initial sync process. Note that this didn't happened on iOS 16 / Xcode 14, so something must have changed to cause this issue. Is there something I need to update on my code to fix this issue, or is it a bug in the OS or frameworks that will be fixed in a future update?
2
1
556
Oct ’23
watchOS 10: CloudKit CoreData Sync (NSPersistentCloudKitContainer) Requires Watch on Charger
I've encountered a significant sync issue with watchOS 10 RC on every device combination I've tested, running both iOS 17 and watchOS 10. I'm curious if others have noticed a similar problem. Context: Standalone watchOS app developed in SwiftUI with a companion iOS app. Both apps use NSPersistentCloudKitContainer for bi-directional CloudKit CoreData Sync between the iOS app and watch. Previously, this sync mechanism was near instant in the foreground and took max 1-2 minutes in the background NSPersistentCloudKitContainer has been reliable since the app was first developed in the watchOS 6/iOS 13 era. Issue: In watchOS 10 RC, sync can take hours--and doesn't even occur when the app is in the foreground. Sync only reliably happens when the watch is placed on the charger, seemingly only if the charge is over 50%. Once taken off the charger, the watch will continue push and receive CoreData changes briefly before becoming unresponsive to sync again. Additional Info: The problem persists even when recompiled with the latest Xcode RC. It's problem is consistent in both production and development CloudKit environments. The CloudKit log shows no watch activity upon CoreData object updates, until placed on the charger (with over 50% charge). The sync starts in the background while the watch is charging. The iOS app, however, reflects immediate activity in the CloudKit log after a CoreData change from the device and reacts promptly to pushes when they eventually occur from the watch. The NSPersistentCloudKitContainer code hasn't changed since it was implemented. Background modes for remote notifications are set correctly, and when sync finally happens, it's accurate. I'm stumped. Perhaps there's a new watchOS 10 setting affecting CloudKit sync QoS? Or could this be a known watchOS 10 RC bug?
12
6
1.6k
Nov ’23
Cloudkit + Watch - Invalid bundle ID for container
I'm running into a problem getting CloudKit to work with a watch app I'm adding to my existing iOS app. I've created a new target for a watch app, and on boot on my real watch, I'm getting the following error: com.apple.coredata.cloudkit.zone:__defaultOwner__ = <CKError 0x14e455f0: "Permission Failure" (10/2007); server message = "Invalid bundle ID for container" My iOS app has the bundle ID of stevenquinn.POS-Chickens and my watch app is stevenquinn.POS-Chickens.watchkitapp. I'm using NSPersistentCloudKitContainer in a shared Persistence file that's accessible by both targets. Both targets have the same iCloud capabilities and containers checked. Any tips on where I might be running wrong?
1
0
364
Sep ’23
How to check if data is fetched from CloudKit?
When using CloudKit in an app, if there are data changes on other devices being synchronized, and you also want to make changes to the data on the current device and reflect it back to the CloudKit server, you might want to display a native loading icon, like the one you see in the Notes app, during this process. How can you implement this? If anyone knows how to do it using SwiftUI, please let me know.
0
0
277
Sep ’23
Using CloudKit as a CDN for premium in-app content
I'm building an app that will provide access to certain CloudKit records but gated by In-App Purchases. My idea is to store these records in CloudKit's public database and I want to know if this is a good idea or not. It seems straightforward enough to prevent the app itself from showing content the user hasn't paid for but the content itself isn't "truly" protected since it lives in CloudKit's public database. Does this seem like a bad idea? If is it, how bad of an idea is it 😅 I'm looking into this approach for costs and the easy of syncing CloudKit records to a Core Data store.
2
0
414
Sep ’23
Xcode 15 RC - CKError: Account temporarily unavailable due to bad or missing auth token
I have two apps which uses the CloudKit public folder so that my users can access data. There's also a private database for them to save data. One is supposed to be able to access the public database without being logged into an iCloud account. And it was working fine. But now, with the simulator, I get the titled error message. It's fine on a device. But, if I log into the simulator with my iCloud account, I can access the public data.
0
0
398
Sep ’23