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

Error loading container details.
#1 As a new starter, I just created a new sample app in Xcode and added iCloud capability. On the CloudKit dashboard I do see the container but selecting the specific container shows the following message in red "Error loading container details." #2 I was able to create a new RecortType via the cloud kit dashboard UI but when I try to create a record form the dashboard UI somehow it does not let me select the record type of the record (I see it in the list but its grayed out). I am not sure what the reason for #1 and #2 and if the two issues are related. Could not find any help online. I am trying to create an app directly with cloudKit and Javascript (not a companion IOS app). Any help would
1
2
1.9k
Aug ’23
Please Create a Sendable Version of CKRecord or Make CKRecord Sendable
CKRecord is a class which does not conform to the Sendable protocol. Its fields consist of NSStrings, NSData and others which are not Sendable. I understand that Apple is incrementally modifying objects to be sendable, but I am experiencing and I would assume others are experiencing a very large number of warnings (for now) about CKRecords and Sendable. It may be too much to make CKRecord Sendable and it may be too much to create a Sendable version of CKRecord, but it would be nice if it could at least be investigated. My particular situation is I have created a Protocol named CKMethods which some of my view controllers use to download and upload CKRecords. I suddenly have a large number of warnings about non-sendable types being sent from main actor-isolated context to non-isolated instance method. The CKRecords sent to and from the protocol do not get mutated and I have never had a problem with data races in the years that I have had this protocol. At some point, the warnings will probably become errors and I definitely do not want to get to that point. I am still coming up to speed on Swift Concurrency, so there may be a more simple solution than the one I am working on - creating a Sendable Struct for every CKRecord type that I have in my app and modifying all of the methods to pass the Struct instead of a CKRecord and convert the Struct to a CKRecord for upload and convert the CKRecord to the Struct for download.
3
1
987
1w
Scrolling in Xcode crash
I have some code from a youtube video that I have completed before, but now when I scroll up, xCode crashes. I have a class with an enum. Sticky headers are there, then as i scroll down, the headers disappear. Then as a // MARK: comes up, we crash. I tried changing the MARK so that it was not bolded, but it still crashes. Is there a setting to disable sticky headers? This was happening in xCode 14.2, and i upgraded, to 14.3, and it went away for a while, but now the problem is back, well intermittently. I did a Clean Build Folder and a Clear All Issues. Still annoying.
3
0
706
Jul ’23
Update Watch Complication with CloudKit
I have an iPhone app the uses CloudKit for Core Data syncing. I also have a companion Apple Watch app that syncs to the same CloudKit records. The watch can be used without the iPhone app as well but they both independently sync to the same CloudKit database. This works reasonably well. As soon as either app is opened, the CloudKit will pull down the latest records. I'd like to add a watch complication that shows the state of the CloudKit records. I supported this by adding a Widget extension, embedded in my watch app. The Core Data database in the watch app is part of an app group, so the complication is able to query the same database. So far so good. I'm running into problems with the complication updating after remote records are changed from the iPhone. Here is what is happening: When records are changed on the iPhone, the data syncs to CloudKit but the watch app is not updated when in the background. This is noticed when you open the app and it takes a second for the view to show the new records. Since Core Data database on the watch is not being updated while in the background, the complication is not being updated at all. Part of my confusion is I assumed CloudKit was meant to make this more seamless with silent push notifications? I have the "Remote Notifications" capability enabled on my WatchApp. It seems that only works while the app is in the foreground though. This seems very limiting when you have a complication that depends on the Watch app's Core Data state. I have a few things to work around this with mixed success: "Wake" the watch app explicitly when records are changed on the iPhone app using WatchConnectivityManager. The hope is that by waking the watch app, it will sync with iCloud. This either isn't working or intermittenly works. It is also not clear to me that by activating the watch app, that it will trigger records to sync. I wish there were a way to ask Core Data to sync explicitly. Whenever the Apple watch app wakes in the last step, ask it to WidgetCenter to reload the widget. This process feels convoluted and seems to negate some of the the benefits of CloudKit to synchronize data which I thought would be baked into this process. Any thoughts on a better approach to all this?
3
1
1.2k
Sep ’23
CloudKit Stopped Syncing after adding new Entities
Can someone please shed some light? I have an app that uses Core Data and CloudKit, up until the last version, I was able to sync data between devices but now after I added two new Entities for some reason it stopped syncing between devices. Here is how I did the change: Created a new Core Data container. Added the new Entities and their Attributes Tested the new Entities locally to be able to send the new schema to CloudKit. Went to CloudKit and made sure that the new Entities and Attributes were reflected on the Developent database. Deploy Schema Cahnges. Went to the Production database to make sure the new schema was deployed; and it was, both databases look the same. Testing: Tested in the simulator and with a real device and everything syncs, even the new Entities. If I download the app from the App Store on two different devices they do NOT sync. Based on the procedure I'm describing above, is there any important step I may have missed when doing the migration? I'm not sure if this is related to the syncing issue but after testing a few times, I no longer can turn the iCloud on, I get the following message when I try to turn iCloud Sync On. CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate resetAfterError:andKeepContainer:]: <NSCloudKitMirroringDelegate: 0x282c488c0> - resetting internal state after error: Error Domain=NSCocoaErrorDomain Code=134410 "CloudKit setup failed because there is another instance of this persistent store actively syncing with CloudKit in this process." UserInfo={NSURL=file:///var/mobile/Containers/Data/Application/73F19BC7-4538-4098-85C7-484B36192CF3/Library/Application%20Support/CoreDataContainer.sqlite, NSLocalizedFailureReason=CloudKit setup failed because there is another instance of this persistent store actively syncing with CloudKit in this process., NSUnderlyingException=Illegal attempt to register a second handler for activity identifier com.apple.coredata.cloudkit.activity.setup.8D4C04F6-8040-445A-9447-E5646484521} Any idea of what could be wrong and preventing the devices from syncing? Any idea or suggestion is welcome. Thanks
3
0
1.7k
8h
Can a private database entity have a relationship to a public database entity?
I’m using NSPersistentCloudKitContainer and I’m utilising the public database and also the user’s private database. For example I have an entity called Category which has a many-to-many relationship to an entity called NewsArticle. So the NewsArticles exist in the public database for the user to browse, but he can add them to a category which will live in his private database. So that’s my question, is it possible for an entity which exists a in the private database to have a relationship to another entity in a public database?
1
1
596
May ’24
CloudKit backed SwiftData @Relationship
Hi, does anyone know how to get @Relationship in SwiftData to cascade to the CloudKit container? I've managed to get SwiftData classes to show up in CloudKit but they are not related in line with the @Relationship as per the example project: @Relationship(.cascade) var bucketListItem: [BucketListItem] = []` They are simply separate records. As result the cascade of deletes doesn't work. Any ideas?
2
0
759
Dec ’23
Enable Permissions (iCloud)
Greetings! In my application I request permission from the user to utilize iCloud. func requestPermission() { CKContainer.default().requestApplicationPermission([.userDiscoverability]) { [weak self] returnedStatus, _ in DispatchQueue.main.async { if returnedStatus == .granted { self?.permissionStatus = true } } } } How can I programatically ask for this permission again via a button? Sometimes a user may deny or disable this permission in error. Thank you! :)
2
0
515
Jul ’23
Limits of CloudKit Public Database
Hello! I would like my users to save short videos (under 30seconds 1080p) to the public database for all other users to download and view. Is this possible? Will I run into any storage pricing with Apple if I were to pursue this as my application backend? I am looking at other methods as well (user sharing from their private database) so I can implement video sharing. Is this feasible and worth pursuing?
2
0
1k
Jul ’23
SwiftData, CloudKit and UIKit - Updating View When Data Changes
I have SwiftData and CloudKit working on a new version of my UIKit app. The current version uses CoreData/CloudKit I have a question. How does one know when there there is new or deleted data to update a view in a UIKit app with SwiftData? CoreData has NSPersistentStoreRemoteChangeNotificationOptionKey. What does SwiftData have that's equivalent? It's not feasible to redo my whole app to use SwiftUI at this stage.
1
1
1k
Jul ’23
Severe hangs with iOS 17 Beta 2 when using iCloud
I have my app including iCloud support in the App Store for many years now. When I run the app on iOS 17 Beta 2 I am experiencing a very bad performance because the main thread seems to be blocked most of the time. When I run the app using the Time Profiler in Instruments it also reports the hangs and the busy main thread. I looked into the profiler window to see methods with long runtime. The most prominent method was: [BRQuery itemCollectionGathererDidReceiveUpdates:deleteItemsWithIDs:] coming from "CloudDocs". That seems to be some iOS internal class. I do not really know where to look next and I want to know whether somebody of you also experienced a similar problem? Thanks, Dirk
0
0
706
Jul ’23
iCloud Drive REST API (POST method)
Guys, can you suggest some keywords about the feature: upload file to iCloud Drive via REST API (POST method)? I did a lot of research in two days and I almost thought it impossible, so I come here to get help from you guys. My project required upload the file into each user's iCloud Drive/Google Drive. For now, I'm finished with Google Drive and it works well. I found CloudKit but seem it's not allowed to upload the file into each user drive like Google Drive The workflow of my feature: Step 1. Upload file to iCloud Drive via REST API Step 2. Get the public share link from the uploaded file in Step 1
0
1
725
Jul ’23
SwiftData CloudKit sync on WatchOS 10
Dear all, Since It is my first apple watch application I just realized that is not possible to use AppGroups to sync between devices and after I spent 5 days in debugging something impossible to do 🙁 ... ... I am now trying to sync between iPhone and AppleWatch using iCloud (CloudKit), SwiftData and the following code (on iOS 17 and Watch OS 10 - beta 3): My Persistency Library public let fullSchema: Schema = Schema([ SWDItem.self, SWDPackage.self ]) public func makeContainer() -> ModelContainer { let configuration = ModelConfiguration( "SWDMyApp", schema: fullSchema, sharedAppContainerIdentifier: "my.appgroup.id", cloudKitContainerIdentifier: "iCloud.my.icloud.id") return try! ModelContainer(for: fullSchema, configuration) } And at the start of the app there is the following configuration as described in SwiftData documentation: iOS/iPad OS @main struct MyApp: App { let container = SWDModelContainer().makeContainer() [...] var body: some Scene { WindowGroup { LaunchScreen() } .modelContainer(container) } And the same for AppleWatch Watch OS 10 @main struct MyAppWatch: App { let container = SWDModelContainer().makeContainer() var body: some Scene { WindowGroup { ContentView() } .modelContainer(container) } } The model configuration is defined in a Swift Package. Therefore the code to configure the model container is exactly the same. The app works perfectly and can store data successfully. Data are persisted. The iCloud sync works between my iPad and my iPhone, BUT NOTHING ARRIVES TO APPLE WATCH. The entitlements of the applewatch is the following: Where iCloud container and AppGroup container match the iOS ones. I am logged in with the same iCloud account in all devices The watch is connected to WiFi Why the SwiftData sync does not work on AppleWatch? What else can I check to make it work? Thanks a lot in advance for your help
2
0
1.8k
Jul ’23
iOS 17 BUG IN CLIENT OF CLOUDKIT: Not entitled to listen to push notifications.
I have a SwiftUI app that uses Core Data and CloudKit. Using the Xcode 15 beta and iOS17 beta simulator, some of the runs cause the app to crash on startup. The console prints the following: BUG IN CLIENT OF CLOUDKIT: Not entitled to listen to push notifications. Please add the 'aps-connection-initiate' entitlement. Push notifications are added correctly and everything works on iOS16 and earlier. This crash also only occurs in about 20% runs on iOS17 beta. Any tips on how to resolve this?
1
0
624
Jul ’23
The model configuration used to open the store is incompatible with the one that was used to create the store.
I have deleted the app and try to run the Xcode project again. How can I remove this error ? Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=134020 "The model configuration used to open the store is incompatible with the one that was used to create the store." UserInfo={NSAffectedObjectsErrorKey=<NSManagedObject: 0x6000021c5310>
2
1
1.2k
Oct ’23
How to sync NSPersistentCloudKitContainer in background after performing AppIntent from widget
I have an app that uses NSPersistentCloudKitContainer and a widget that displays a record. I want to add a button with interactive widgets in iOS 17 to modify the visible record via an AppIntent. When I do this the app logs: CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate managedObjectContextSaved:](2945): <NSCloudKitMirroringDelegate: 0x2818002a0>: Observed context save: <NSPersistentStoreCoordinator: 0x280a05180> - <NSManagedObjectContext: 0x281a00410> It does not automatically sync this change to iCloud, not until I manually return the app to the foreground, even if I delay returning from the perform() function. Is there a way to sync NSPersistentCloudKitContainer while the app is in the background as a result of this change triggered in the widget? Thanks!
2
1
613
Jul ’23
CoreData data disappears locally after disabling iCloud in device Settings
I've built an app and got it working nicely with CoreData, and now I want to integrate it with CloudKit. I have made some minor changes to my code (namely updating NSPersistentContainer to NSPersistentCloudKitContainer and CloudKit works - I can see records appearing in the iCloud dashboard and I can modify records from the iCloud dashboard and the changes reflect on my device. Great. However, if I disable iCloud syncing via Settings on my device (without force-quitting my app) I notice a couple of things: When switching back to my app if I try and edit an entity I sometimes get an app crash If I quit and reload the app all my data has disappeared from my device (it still remains in iCloud). Is this expected behaviour? Ideally, what I would like, is that the data persists locally if a user has added records but then later decides to disable iCloud syncing on the app. Here's my code in case I've done anything funky with the implantation. It feels pretty simple, but maybe that's the problem. CoreDataManager.swift: class CoreDataManager { static let shared = CoreDataManager() lazy var persistentContainer: NSPersistentCloudKitContainer = { setupPersistentContainer() }() private func setupPersistentContainer() -> NSPersistentCloudKitContainer { print("setup") let container = NSPersistentCloudKitContainer(name: "TestApp") guard let storeDescription = container.persistentStoreDescriptions.first else { fatalError("Could not load store description.") } storeDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) storeDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) container.loadPersistentStores { (_, error) in if let error = error as NSError? { fatalError("Unresolved error when loading CoreData persistent stores: \(error), \(error.userInfo)") } } container.viewContext.automaticallyMergesChangesFromParent = true container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy return container } } The CoreDataManager class is then called from my main App.swift file when assigning the MOC: @main struct Main: App { // // MARK: Properties // @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate // CoreData context let moc = CoreDataManager.shared.persistentContainer.viewContext // // MARK: Initialisation // var body: some Scene { WindowGroup { Test() .environment(\.managedObjectContext, moc) } } } And finally the Test.swift (as a very basic example) struct Test: View { @FetchRequest(sortDescriptors: []) var people: FetchedResults<Person> var body: some View { List(people) { person in Text(person.name ?? "Unknown") } } } Any sage advice would be welcome as I'm tearing my hair out over this. Is my approach even correct/what's the expected behaviour here?
1
0
486
Jul ’23
Production and Testflight app coredata react as separate instance
I wanted to bring to your attention an issue recently identified regarding the accessibility of existing production core data on our TestFlight app. Following the completion of a core data migration process, accessing the aforementioned production data has become temporarily unavailable on the TestFlight platform. If I install the testflight app getting a new instance of core data. whereas in production another instance of core data. respectively after lightweight migration data are not merging.
0
0
490
Jul ’23