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.

CloudKit Documentation

Posts under CloudKit tag

247 Posts
Sort by:
Post not yet marked as solved
1 Replies
481 Views
In NSFileManager there is this method to move files to and from iCloud:- (BOOL)setUbiquitous:(BOOL)flag itemAtURL:(NSURL *)url destinationURL:(NSURL *)destinationURL error:(NSError **)errorOutAll the samples and information I'm able to find seem to be related to using NSDocument, which my app isn't using. I have a little view in my app that allows users to move an image out from the iCloud container and into a local directory. It seems that simply using NSFileManager moveItemAtURL:toURL:error: works fine both to move a file in and out of the iCloud container on OS X without wrapping everything in a file coordinator block. Is it still necessary to use a file coordinator to move files out of iCloud on the Mac. When I put a file in the iCloud container, the system automatically starts uploading it..even though I'm not using a file coordinator...and my related file presenter still is detecting a change.Both methods seem to be working the same, I'm just wondering if I should be using a coordinator because it's a good amount of code I can get rid of if it's not necessary.Thanks.
Post not yet marked as solved
4 Replies
2.6k Views
According to Apples Class Reference CKQuery, the operator "CONTAINS" is one of the suported operators. However, that doesn't seem to work. I have a recordtype called myRecord, and a record with filedname "name" type String. I try to fetch the record with two different predicates, one with "==" operator, and one with "CONTAINS" operator.func getRecords(){ let name = "John" let Predicate1 = NSPredicate(format: "name == %@",name) let Predicate2 = NSPredicate(format: "name CONTAINS %@",name) let sort = NSSortDescriptor(key: "Date", ascending: false) let query = CKQuery(recordType: "myRecord", predicate: Predicate1) //let query = CKQuery(recordType: "myRecord", predicate: Predicate2) query.sortDescriptors = [sort] let operation = CKQueryOperation(query: query) operation.desiredKeys = ["name", "Date"] operation.recordFetchedBlock = { (record) in print(record["name"]) operation.queryCompletionBlock = { [unowned self] (cursor, error) in dispatch_async(dispatch_get_main_queue()) { if error == nil { print ("sucess") } else { print("couldn't fetch record error:\(error?.localizedDescription)") } } } CKContainer.defaultContainer().publicCloudDatabase.addOperation(operation) }Using Predicate1, outout is: Optional(John) sucessUsing Predicate2, outout is: couldn't fetch record error:Optional("Field \'name\' has a value type of STRING and cannot be queried using filter type LIST_CONTAINS")Also using [c] to ignore casings gives a crash.How do I use the operator "CONTAINS" correctly, and how do I ignore letter casings?
Posted
by
Post not yet marked as solved
2 Replies
1.1k Views
Hello.I am starting working with theCloudKit Web ServicesI am reading the documentation here:https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/CloutKitWebServicesReference/SettingUpWebServices/SettingUpWebServices.html#//apple_ref/doc/uid/TP40015240-CH24-SW1I am trying to receive Getting the Web Authentication TokenAfter successfully login I am getting this jsonObject appInfo:Object AdditionalSalt:"cec2731125ded8d34cbd3702e0c360b8b7b534fa04dbb2f0ea150b524b7739e5"AppDiscoverable:"false"AppId:"0"AppName:"iCloud.jovan.PhotoWebApp"ContainerEnvironment:"development"ContainerId:"iCloud.jovan.PhotoWebApp"DeveloperName:"UNKNOWN_DEVELOPER"LogoURL:""__proto__:ObjectckSession:"48__24__AZLhIol7ffB34oNYrGP54rWKY5MiVdO+2+85oIiWPuKoK/KJ7r9cNivNwYd03iX/aDW6KL4wuAOVJZ0dAShqhT9ZhoUuW9ZZNPPQ7tzTcBNJ/itQI/uulkBi/51Rpijv/5ZypUYD9yGP3dyXQgDVlGSK8tUPHigigN7nO91DGkM1kaT11lXFBBCHlvZr0DX4tp1cxZ9/P/Q=__eyJYLUFQUExFLVdFQkFVVEgtUENTLUNsb3Vka2l0IjoiUVhCd2JEb3hPZ0VpWXd2Q0QyYmdCVWZrblo1cmp3dnl3Wjg1cHF1dTdLaFZPMThnMEx1bDhLeWRhMHR5SkhyUkZwT0JycEVicXNXWGhqUk9XbTlyd2pkZzB6K3JvZktOIiwiWC1BUFBMRS1XRUJBVVRILVBDUy1TaGFyaW5nIjoiUVhCd2JEb3hPZ0ZyZzEyZGNZSGk4WWRKYU0yK1pFMFRKaytrdTBBMmNZTG8vaUJPRlV1cEtKT3ExS1YvYjlBaldCeklwQTR5N2FUbXNrMDhCWjRsYVRoeWRTaSt3eE9PIn0="isICDP:falsepcsDeleted:falsepermissions:Array[1] 0:Object ask:falsename:"discoverability"__proto__:Objectlength:1__proto__:Array[0]status:0But, as per documentation I should receive the ckWebAuthToken instead of ckSessionCould you please help me? Looks like documenttion is incorrect or i do something wrong...How to get the ckWebAuthToken or how to use this ckSession for requesting the web services?
Posted
by
Post marked as solved
3 Replies
1.8k Views
Hello,I am creating a new app that uses CKShare. I am able to create the CKShare and send it by email using UICloudSharingController.When the receiver of the invite tries to accept the share, there is an error message"Couldn't open "Title"You need a newer version of "App" to open this, but the required version couldn't be found in the App StoreMy app has not been published to app store yet. How do I resolve this error? I am using a development build with two apple id's to test ckshare.Thanks!
Posted
by
Post not yet marked as solved
5 Replies
2.8k Views
Hi all,I am having trouble sharing a record. I have successfully saved the record to my private database in a custom zone, and I have successfully created a share email to that record. I have accepted the share and I now see the record in the share database of the recipient under the same zoneID. In the DB, it shows also that the share has been accepted.When I click on the share link and bring up the app, I get this message in the console:2019-04-05 13:21:11.553916-0300 StoryWheel[41594:6905300] [LogFacilityCK] You cannot get the URL of a share until it's been saved to the server2019-04-05 13:21:11.559670-0300 StoryWheel[41594:6905300] -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:]: Handling CloudKit Share Action with metadata: <CKShareMetadata: 0x6000017740a0; shareID=<CKRecordID: 0x60000261c9a0; recordName=Share-9F2CE009-3AC0-4658-AC0A-E4FE33664068, zoneID=storywheel:_1b1d6baf4f1340d8a7d80abf12a31551>, Owner=<CKUserIdentity: 0x60000027adc0; lookupInfo=<CKUserIdentityLookupInfo: 0x60000280d4a0; email=awilcox@***.ca>, cached=0, nameComponents=Andrew, userID=<CKRecordID: 0x60000261cfsx0; recordName=_1b1d6baf4f1340d8a7d80abf12a31551, zoneID=_defaultZone:__defaultOwner__>, contactIdentifiers={ items = ( );}>, participantStatus=Accepted, container=iCloud.ca.***.storywheel1:Sandbox, rootRecordID=<CKRecordID: 0x60000261ce80; recordName=D3D7F7BF-46B1-4CE0-8620-FE1919BD9A66, zoneID=storywheel:_1b1d6baf4f1340d8a7d80abf12a31551>, participantPermission=ReadWrite, shareURL=<null>, participantRole=PrivateUser>Not sure I understand the error message, as the record seems to be on the server. Anyone else seen this?Thanks,Andy
Posted
by
Post marked as solved
9 Replies
7.5k Views
Hello, I'am an Unity game developer. Iam using custom Binary files to save game progress data (encoded strings, int, bool etc.). Now before I build my project/game to Xcode and upload it to the Appstore, I want the user to be able to save their progress to the iCloud so they can play on multiple devices and restore/override their game data if needed. However I can't find online a step for step guide on how to achieve this. The data that I would need to store for 1 user would probably not be more then 100 int/bool/float etc. I want to know what "Cloud system" I should use in my situation, and how to synchronize my binary files to iCloud. Help would very much be appreciated!
Posted
by
Post marked as solved
8 Replies
2.9k Views
I’m slightly confused about how are CloudKit containers supposed to handle app transfers. I’m seeing some strange too-permissive security behavior, and I am not sure whether this is a feature or a bug 🙂Here’s the setup:I had an app with bundleID com.example.something, talking to a CloudKit container also called com.example.something, all under the same developer account A. All was well.I then transferred the app from developer account A to developer account B. The bundle ID or anything else about the app did not change, just the ownership. Must now also sign new builds of the app with credentials for account B, as expected. HOWEVER: the CK container also did not change at all, and remained under development account A.What I am seeing now: the app signed by developer account B can still access the CK container under developer account A. No bundle IDs or CK ID-s changed, so I can sort of understand this, but at the same time, it seems strange.There is no security risk to my data, as this app only uses "read" operation of the public database. I didn’t try any other operations or private databases.Is this a bug and could it stop working? Or is this a feature which will remain working? This tells me that under certain conditions, any app can read the CK container of any other app from any developer account, if they know the correct CK container ID to talk to. Is this expected? (Or maybe it only keeps working because they were previously under the same developer account, and the system knows to keep this connection? And if I were try to randomly read any other app’s container, it would fail?) Any docs or guidance from Apple?
Posted
by
Post not yet marked as solved
11 Replies
6.9k Views
Any insights on how to incorporate CloudKit (or CoreData) in the WidgetKit extension? Where in the WidgetKit api do I make the asynchronous call to load the data to be available for the TimelineProvider?
Posted
by
Post not yet marked as solved
2 Replies
1.3k Views
I use NSPersistentCloudKitContainer. It seems that it the data synced in iCloud after a few seconds. However, I get the following warnings in the console. I do not understand what is it for. CoreData: warning: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _performSetupRequest:]_block_invoke(813): &lt;NSCloudKitMirroringDelegate: 0x280b051e0&gt;: Successfully set up CloudKit integration for store: &lt;NSSQLCore: 0x280024a00&gt; (URL: file:///private/var/mobile/Containers/Shared/AppGroup/89D9D17C-03DF-48E4-83C3-DB23A8FE0D6F/TestData.sqlite) CoreData: warning: CoreData+CloudKit: -[NSCloudKitMirroringDelegate checkAndScheduleImportIfNecessary:]_block_invoke(2033): &lt;NSCloudKitMirroringDelegate: 0x280b051e0&gt;: Scheduling automated import with activity: <CKSchedulerActivity: 0x281f51590; additionalXPCActivityCriteria={     Priority = Utility; }, containerID=&lt;CKContainerID: 0x283c612e0; containerIdentifier=iCloud.io.test.testData, containerEnvironment="Sandbox"&gt;, identifier=com.apple.coredata.cloudkit.activity.import, priority=2> Could you please explain what is this warning for and what should I do to fix it?
Posted
by
Post not yet marked as solved
1 Replies
479 Views
TL;DR: I'm syncing a local database to CloudKit and I'd like to store only the CKRecord's recordChangeTag locally, because the archived system fields are quite large. Is there any way to create a CKRecord with a given recordChangeTag? I'm working on syncing an on-device database to CloudKit. As part of this I need to remember the CloudKit state of every database record, so I when that record changes I can create a CKRecord for it and push it to the server. The supported way to do this is to call CKRecord.encodeSystemFields on the resulting record after the push, and save that archived data alongside the local record so it can be reconstituted into a CKRecord next time I need to push that database row. The problem is that this archived data is pretty heavyweight, generally about 1600 bytes. That's not a lot for one record, but for 60,000 records it's 100MB of extra data to store (and read and write.) As far as I can tell, the only really crucial part of a CKRecord to push (besides the ID and type, which I already know) is the recordChangeTag — this is what the server uses as the MVCC token to reject conflicting updates. And this tag is tiny: it appears to be a hex-encoded generation count, so it's usually 1 or 2 bytes. I'd like to store just this tag. But I can't use it to reconstitute a CKRecord, because that property isn't settable. Is there any workaround?
Posted
by
Post not yet marked as solved
1 Replies
613 Views
I used a renaming identifier to rename an Entity Name, but it doesn't seem to work and it causes a crash at start during in-place migration. How to rename an Entity Name when using NSPersistentCloudKitContainer? I get this exception at start: CloudKit integration forbids renaming 'OldEntityName' to 'NewEntityName'. Older devices can't process the new records. Unresolved error Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." App is not in production, need a way to rename 'OldEntityName' to 'NewEntityName'. How to achieve this?
Posted
by
Post marked as Apple Recommended
4.6k Views
I've been using CloudKit for my app recently and I'm trying to add support for a WatchOS app and I've enabled iCloud in capabilities and ticked the container I want to use but I get this error. CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate recoverFromPartialError:forStore:inMonitor:]block_invoke(1943): <NSCloudKitMirroringDelegate: 0x282430000>: Found unknown error as part of a partial failure: <CKError 0x28112d500: "Permission Failure" (10/2007); server message = "Invalid bundle ID for container"; uuid = ; container ID = "iCloud.Appname"> I tried creating a new container which worked for both the watch app and iOS app however I would like to use my original container since it has my old data
Posted
by
Post not yet marked as solved
1 Replies
642 Views
Hi. Didn't find the answer in the documentation. Are CloudKit procedures executables in background tasks ? I'm trying to do : "[privateDatabase fetchRecordWithID:myMasterRecordID completionHandler:^(CKRecord *myMasterRecord, NSError *error) { ... }]" but it returns a record only when the app is active. In background task, it does nothing and waits until app is active. Thanks for you answer. Best Claude
Posted
by
Post not yet marked as solved
1 Replies
617 Views
I have an existing app which uses a JSON-based file format currently saved to Application Support (so not user visible). It only needs a single data store per-user. I would like to integrate it with iCloud to make this file available on other devices. Is it considered acceptable to use UIDocument on its own for loading/saving the single file? By this I mean without using UIDocumentBrowserViewController or another file picker. Just my app loading right into the main UI but using UIDocument to open/read/save/close the data file. I am hoping this would allow me to let UIDocument do most of the boilerplate work around NSFileCoordinator and NSFilePresenter. Can anyone confirm if this is a thing that is known to be OK? Or am I going against the frameworks here?
Posted
by
Post marked as solved
6 Replies
1.1k Views
I have an app that is already running with CoreData, and I want to allow the users to upload their data to iCloud so, in the case they need to delete their apps or change devices, they don't lose it. Every time the app is opened, there is a synchronization that happens between CoreData and a JSON file fixture, in order to fill the app with its base values (creating NSManagedObject instances from the aforementioned fixture). Before the iCloud sync, the CoreData model had some constraints for different entities, to enforce uniqueness, but these had to be stripped since CloudKit doesn't support them. Most of these constraints were basically ids that came from the JSON and represent an item in our Firebase database. Given that, I want to make the underlying CKRecord.id the same as these ids, so I can avoid the situation where, if a person open the app in a second device, the fixture data is repeated, since the fixture runs before the sync with the iCloud happens. Is that possible? Any help would be appreciated.
Posted
by
Post not yet marked as solved
3 Replies
3.5k Views
The call stack is followed: Incident Identifier: 5DBD18B5-29DD-48E1-8BE5-A648BD4E8CE3 CrashReporter Key: 4006fd6d63831c08be5068429b9892f633d41735 Hardware Model: iPhone12,5 Process: *** Path: /private/var/containers/Bundle/Application/FD114B6F-9C45-4546-9924-082A2CF546B8/***.app/*** Identifier: com.***.*** Version: 2.0.0 (2.0.0.3) AppStoreTools: 13A227 AppVariant: 1:iPhone12,5:13 Code Type: ARM-64 (Native) Role: Unspecified Parent Process: launchd [1] Coalition: com.***.*** [2761] Date/Time: 2021-09-28 14:24:03.8329 +0800 Launch Time: 2021-09-28 14:24:03.5890 +0800 OS Version: iPhone OS 15.0 (19A346) Release Type: User Baseband Version: 3.00.00 Report Version: 104 Exception Type: EXC_GUARD Exception Subtype: GUARD_TYPE_USER Exception Message: namespc 18 reason_code 0x0000000000000002 Exception Codes: 0x6000000000000012, 0x0000000000000002 Exception Note: SIMULATED (this is NOT a crash) Termination Reason: LIBSYSTEM; [2] Thread 3: Crashed 0 libsystem_kernel.dylib 0x1b80a2ae8 os_fault_with_payload + 7382641384 ((null)) 1 libsystem_trace.dylib 0x000000019bd941b4 _os_log_impl_flatten_and_send + 6909673908 ((null)) 2 libsystem_trace.dylib 0x000000019bd90b70 _os_log + 6909660016 ((null)) 3 libsystem_trace.dylib 0x000000019bd98cac _os_log_fault_impl + 6909693100 ((null)) 4 SyncedDefaults 0x1ad034c90 -[SYDRemotePreferencesSource initWithApplicationID:storeID:shared:additionalSource:containerPath:storeType:].cold.1 + 52 5 SyncedDefaults 0x1ad027210 -[SYDRemotePreferencesSource initWithApplicationID:storeID:shared:additionalSource:containerPath:storeType:] + 1400 6 Foundation 0x182ff5d58 -[NSUbiquitousKeyValueStore initWithBundleIdentifier:storeIdentifier:additionalStore:storeType:] + 348 7 Foundation 0x182fd8e84 __41+[NSUbiquitousKeyValueStore defaultStore]_block_invoke + 24 8 libdispatch.dylib 0x000000018140194c _dispatch_client_callout + 6463428940 ((null)) 9 libdispatch.dylib 0x00000001814031d4 _dispatch_once_callout + 6463435220 ((null)) 10 Foundation 0x182fe0668 +[NSUbiquitousKeyValueStore defaultStore] + 64 ... // omit insignificant call stack of the app 14 libdispatch.dylib 0x00000001813ffc00 _dispatch_call_block_and_release + 6463421440 ((null)) 15 libdispatch.dylib 0x000000018140194c _dispatch_client_callout + 6463428940 ((null)) 16 libdispatch.dylib 0x0000000181413064 _dispatch_root_queue_drain + 6463500388 ((null)) 17 libdispatch.dylib 0x0000000181413764 _dispatch_worker_thread2 + 6463502180 ((null)) 18 libsystem_pthread.dylib 0x00000001f12c5170 _pthread_wqthread + 8341180784 ((null)) 19 libsystem_pthread.dylib 0x00000001f12c4f4c start_wqthread + 8341180236 ((null)) What's mean the Exception Note: SIMULATED (this is NOT a crash)? It's not a crash? And then, is it possible a bug in iOS 15?because no crash reports before iOS 15. Thanks.
Posted
by
Post not yet marked as solved
1 Replies
780 Views
In my app I have a defaultJournal: Journal, that automatically gets added on the user's device on launch. There should only be one "default" journal, and I know that deduplication as shown in the Apple Demo, is the correct approach to ensure this on multiple devices. Journal looks something like: class Journal: NSManagedObject { @NSManaged var isDefaultJournal: Bool @NSManaged var entries: Set<JournalEntry>? } Since Journal has a relationship to entries, how can I deduplicate it ensuring that I don't orphan or delete the entries? I am worried that the entries aren't guaranteed to be synced, when we discover a duplicate journal in processPersistentHistory. This would lead to either orphaned or deleted entries depending on the deletion rule. How can one handle deduplicating entities with relationships? For example here is my remove function:     func remove(duplicateDefaultCalendarNotes: [Journal], winner: Journal, on context: NSManagedObjectContext) {         duplicateDefaultCalendarNotes.forEach { journal in             defer { context.delete(journal) } // FIXME: What if all of the journal entries have not been synced yet from the cloud? // Should we fetch directly from CloudKit instead? (could still lead to orphaned/deleted journal that have not yet been uploaded)             guard let entries = journal.entries else { return }             entries.forEach {                 $0.journal = winner             }         }     } A missing tag on a post isn't that bad, but deleting a user's journal is unacceptable. What is the best strategy to handle this?
Posted
by
Post not yet marked as solved
3 Replies
1.7k Views
I have a music app that can play in the background, using AVQueuePlayer. I'm in the process of adding support for CloudKit sync of the CoreData store, switching from NSPersistentContainer to NSPersistentCloudKitContainer. The initial sync can be fairly large (10,000+ records), depending on how much the user has used the app. The issue I'm seeing is this: ✅ When the app is in the foreground, CloudKit sync uses a lot of CPU, nearly 100% for a long time (this is expected during the initial sync). ✅ If I AM NOT playing music, when I put the app in the background, CloudKit sync eventually stops syncing until I bring the app to the foreground again (this is also expected). ❌ If I AM playing music, when I put the app in the background, CloudKit never stops syncing, which leads the system to terminate the app after a certain amount of time due to high CPU usage. Is there any way to pause the CloudKit sync when the app is in the background or is there any way to mitigate this?
Posted
by
Post not yet marked as solved
1 Replies
987 Views
I'm using NSPersistentCloudKitContainer with Core Data and I receive errors because my iCloud space is full. The errors printed are the following: <CKError 0x280df8e40: "Quota Exceeded" (25/2035); server message = "Quota exceeded"; op = 61846C533467A5DF; uuid = 6A144513-033F-42C2-9E27-693548EF2150; Retry after 342.0 seconds>. I want to inform the user about this issue, but I can't find a way to access the details of the error. I'm listening to NSPersistentCloudKitContainer.eventChangedNotification, I receive a error of type .partialFailure. But when I want to access the underlying errors, the partialErrorsByItemID property on the error is nil. How can I access this Quota Exceeded error? import Foundation import CloudKit import Combine import CoreData class SyncMonitor { fileprivate var subscriptions = Set<AnyCancellable>() init() { NotificationCenter.default.publisher(for: NSPersistentCloudKitContainer.eventChangedNotification) .sink { notification in if let cloudEvent = notification.userInfo?[NSPersistentCloudKitContainer.eventNotificationUserInfoKey] as? NSPersistentCloudKitContainer.Event { guard let ckerror = cloudEvent.error as? CKError else { return } print("Error: \(ckerror.localizedDescription)") if ckerror.code == .partialFailure { guard let errors = ckerror.partialErrorsByItemID else { return } for (_, error) in errors { if let currentError = error as? CKError { print(currentError.localizedDescription) } } } } } // end of sink .store(in: &subscriptions) } }
Posted
by
Post not yet marked as solved
1 Replies
473 Views
Hi everyone, we recently integrated UICloudSharingController to share cloudkit records on one of our apps, but we noticed while testing that the icloud share link opens the wrong app on App Store if we invite a participant who has not the app installed on his device. We thought it was because for another our app (app store opens the download page for this app) we basically duplicated the same coredata/cloudkit implementation, forgetting maybe some cloudkit references of the first app and indeed we noticed a wrong icloud container assignment for the second app, which essentially had two containers, the correct one (its own) and the one of the first app (the wrong one). So, we fixed the problem, every app has his own container now and only his own, and we updated the provisional profiles as well, in order to have the correct icloud containers entitlements. Unfortunately the problem persists and after check everything else (containers, app groups, PersistentStoreDescriptions etc.) we don't have any more ideas. What else should we check? Thanks in advance for your suggestions. Some more detail of the issue: If we have the app installed on the device the icloud share link opens the right app. The same icloud share link works properly on Mac Catalyst (the App Store opens the correct app page if we don't have the app installed). The problem is only on iOS.
Posted
by