FAQ Database Discussion Community

CKFetchRecordsOperation + CKQueryOperations … what am I missing?

Managed to cobble together a CKFetchRecordsOperation after much searching for sample code; and here it is... but I must have missed something. Don't get me wrong it works a treat... but... To execute a CKFetchRecordsOperation you need an NSArray of CKRecordIDs; to get a NSArray of CKRecordIDs, you need to...

CKAsset won't show in tableview image

I have an optional image in the cloudkit DB(checked DB and the image is there in cases where I added it in my testing). I have created a class that initializes the record fields into variables I use in my tableview. I have a custom cell as well. But the...

CloudKit: Order query results by creation date

When loading items from CloudKit I would like to order the results by creation date. I believe now it's sorting by the first property of the record. func loadItems() { let predicate = NSPredicate(value: true) let query = CKQuery(recordType: "Items", predicate: predicate) db.performQuery(query, inZoneWithID: nil) { (results, error) -> Void...

Keep order of NSArray with CloudKit

I'm currently designing a CloudKit based syncing-solution and I wondered what the best way is to keep the order of a list (an array in my case) of cloud items (CKRecord objects) consistent. Apple advises against holding a reference to child objects and instead just reference the parent object with...

Find User Name or First/Last Name in iOS9 CloudKit / ABPerson (ABAddressBook)

iOS9 deprecates user info features for CloudKit and for ABPerson. e.g. in the properties of CKDiscoveredUserInfo firstName" Deprecated in iOS 9.0 lastName" Deprecated in iOS 9.0 I want last name and first name as previously provided in iOS8 CloudKit. How to retrieve the similar information in iOS9 CloudKit, ABPerson or...

Deleting data from cloudkit with swift

How do I delete some data I put into the cloud? I made an app that when you enter a url in 1 view controller it uploads into the cloud, and when you go to another view controller it shows the url you entered before from the cloud in a...

CloudKit ___recordID is not marked queryable

I tried to save data to the CloudKit programmatically with success but I got an error when I fetch data from CloudKit I got an error > <CKError 0x608000052060: "Invalid Arguments" (12/2015); server message > = "Field '___recordID' is not marked queryable"; uuid = 19F1E556-5384-42FD-8F65-9FD8A9C9523D; container ID = > "iCloud.com.mywebsite.CloudDemo">...

Curious whether fileUrl of CKAsset can change with time?

I am caching CKRecord on client and fileUrl of CKAsset too. Can fileUrl change from time to time? Asset / data itself is not changing.

CloudKit subscriptions in the private database

I have an app for which I want to add the possibility to backup data to iCloud using CloudKit. The "backup" part seems to work correctly (my records are in the private database, since they are ... well, private). Now I would like to use CKSubscriptions to keep all my...

Since iOS8 we should use CloudKit for all iCloud apps?

I've noticed a lot of people creating iCloud apps using Obj-C and importing .h etc. To a noob like me it seems very complex since I've been using Swift from the beginning. People say iCloud apps can be created using only Swift and CloudKit exclusively. Is it possible? Thanks

CloudKit: “There is no operation associated with this request”

When attempting to save a CloudKit CKRecord, I get a CKError returned which gives the following description: <CKError 0x7fd3d24e1810: "Internal Error" (1/2005); "there is no operation associated with this request"> Any ideas what might cause this? Google does not return any results at all to this error....

CKAccountStatus returning different values when not called from ViewController

I'm using Cloud Kit in my app which makes use of the camera and only allows the user to submit photos if they're logged into iCloud. So when the user clicks the camera button, I call a CloudKit method to get the user's icloud status, which returns a CKAccountStatus value...

cloudkit: how to access main user's attributes?

I am fairly new to programing and a total newbie regarding cloudkit. I am trying to make an app in which every user would have a personal avatar, a nickname and so on. The problem is that I don't know how to access the user's account on cloudkit. My solution...

How to fetch list of CKRecordIDs

I'd like to be able to download a list of all CKRecordIDs of a certain record type from a Cloud Kit database. I don't want the records themselves, since they have large assets that aren't needed until the user asks for them. CKQuery seems to return CKRecords only. Any ideas?...

Type anyObject? does not conform to 'StringLiteralConvertible'

I am trying to add pictures stored as CKAssets to an array in a collection view, however my query to bring back the images is giving me an error that I can't figure out. Can anyone help me out? My code is: class Query: UIViewController { override func viewDidLoad() {...

cloudkit enter userID as reference of a new record (in code)

I am setting an app in which a user could create records. Let's say he/she is the owner of a chatroom. Therefore there is an attribute called "admin" in the chatroom record. This attribute takes a reference which is the ID of the owner. Here is what I tried: CKContainer.defaultContainer().fetchUserRecordIDWithCompletionHandler({...

Swift / Cloudkit predicate format

I am trying to write a predicate using coordinates stored in a CloudKit database. I am struggling to find any accurate documentation on the way to format it. Here is what I've come up with: NSPredicate(format: "distanceToLocation:fromLocation: (%K,%@) < 1000", "locationcoordinates") I am getting the following error: Terminating app due...

How to approve uploads to CloudKit

When creating an application that uses CloudKit, sometimes you allow the user to create and upload data to the public database which will be publicly available to everyone once it's created. This leads to my question which is: How do you review/moderate/approve user created data before making it available to...

discoverAllContactUserInfosWithCompletionHandler faster?

How can I create a CKOperation with higher priority than the default for discoverAllContactUserInfosWithCompletionHandler? I can't find an example of querying all user info without using [[CKContainer defaultContainer] discoverAllContactUserInfosWithCompletionHandler: which is pretty low priority and takes forever to complete....

How to delete a CKRecord

How do I delete a CKRecord from my database programmatically, on the client side. for record in records { if recordNumber < 13 { let moodRecord:CKRecord = record as! CKRecord self.moodArray.append(moodRecord.objectForKey("Color") as! String) } else if recordNumber > 13 { // DELETE RECORD HERE record.delete(CKRecord) recordNumber-- } recordNumber++ } ...

“Asset File Not Found” (16/3002); “Can't read the file”

I want so save an CKAsset and I get back this error: Asset File Not Found" (16/3002); "Can't read the file Any idea?...

Query CloudKit database with multiple record types

I have a cloud kit database set up and am trying to query against it. It looks like predicates won't work for what I'm trying to do. In SQL the query would look something like this: SELECT type1 FROM table1, table2 WHERE table1.columnA = table2.columnB Also, similar to: NSPredicate(format: "%K...

Cast / convert dictionary in Swift

How can I convert an [NSObject : AnyObject] -> [NSString: CKRecordValue] in Swift? personEdited!.changedValues() as [(NSString, CKRecordValue)] personEdit in a NSManagedObject. ...

Any drawback if CKRecordID.recordName is generated on client?

It could provide a more smooth user experience if recordName is generated on client. var uuid = NSUUID().UUIDString Do you know any disadvantage to do it?...

Creating a User record based on currently logged in Apple ID

Using Objective-C is there a way I can create a new user to an app based on their apple ID automatically. I would be using this in conjunction with CloudKit In order to create and auth users without creating a whole 'login' and 'sign up' view

Core Data with CloudKit

When using Core Data with CloudKit, does the iCloud container (ubiquity container) containing the copy of sqlite db still exist at local device?

Nested CloudKit queries and UITableView

I am trying to make a simple table-based app using CloudKit that allows you to drill down to find more information about a particular item. Let's say my app shows a directory of shops located inside theme parks, divided by sections of the park. In my initial table view, I...

How can I speed up performQuery in Swift?

So I am creating this app that uses CloudKit to save and fetch images and text from the Cloud. The problem is that I can only access the results after the whole fetch is done. I would like to be able to fetch each record individually as it is fetched....

Reloading CloudKit data when app comes to foreground

I'm trying to understand CloudKit, but I'm having an issue figuring out a real-world issue if I eventually turned it into an app. I've got a tableviewcontroller that's populated by CloudKit, which works fine. I've got a detailviewcontroller that is pushed when you tap one of the entries in the...

Possible to set default CloudKit container not based on application name?

When I turn on CloudKit in Xcode, it set and create a default container based on the name of the app. Is it possible to set a different default name? I do not want to see a new container name on the list in CloudKit dashboard, but use an existing...

CloudKit Unexpected Expression for NSPredicate

I'm using CloudKit and wish to perform a search for records based on their string fields. Apple docs say this is the way to do a tokenized search of a record's fields: To perform a tokenized search of a record’s fields, use the special operator self. A tokenized search searches...

Xamarin developed app using CloudKit is still cross-platform?

Read here an article how CloudKit can be accessed / used from Xamarin. Does it mean Android version still able to access / store data in CloudKit?

Predicate comparing two keys

I am trying to write a predicate to compare two keys in a cloud kit database. All the documentation I've been able to find only allows you to compare one key against a set value. Is there a way to write a predicate in swift to compare two keys? The...

CloudKit. Problems with subscriptions

I do not quite understand the information about subscriptions. I have Private Database. There is a table to which I create a subscription. If I subscribe to two devices under one iCloud account, errors occur: Subscribed with error: CKError 0x165c6ac0: "Server Rejected Request" (15/2032); server message = "subscription is duplicate...

CloudKit compound query (query with OR)

I would like to query CloudKit using OR with two fields. But I can't find a way how to do this. What I did is: NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"(creatorUserRecordID == %@)", userId]; NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"(toUser == %@)", userId]; NSCompoundPredicate *compPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[predicate1, predicate2]]; CKQuery *query =...

CloudKit: Fetch all records with a certain record type?

I have currently got CloudKit set up in my app so that I am adding a new record using the help of the following code below, CKRecordID *recordID = [[CKRecordID alloc] initWithRecordName:@"stringArray"]; CKRecord *record = [[CKRecord alloc] initWithRecordType:@"Strings" recordID:recordID]; [record setObject:[NSArray arrayWithObjects:@"one", @"two", @"three", @"four", nil] forKey:@"stringArray"]; [_privateDatabase saveRecord:record completionHandler:nil];...

NSPredicate with OR returning error

I have a problem with the following predicate: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(creatorUserRecordID == %@) OR (toUser == %@)", userId, userId]; When I use it in query CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Message" predicate:predicate]; I have an error that says: 'CKException', reason: 'Unexpected expression'. When I use these two seperately...

How to connect CKQueryNotification to a CKRecord or CKSubsription?

I need a way to connect a CKQueryNotification to a CKRecord or CKSubscription so I can receive updates/inserts/deletes on multiple record types. I'm successfully receiving CKNotifications and this is the payload: { ck = { ce = 2; cid = "<my cloud container id>"; nid = "<unknown guid>"; qry =...

When CloudKit error occurs should client keep resending?

When client get a CKErrorRequestRateLimited client should perform operation again after RequestRateLimited sec. But what do you do when get some different error type i.e. CKErrorZoneBusy. How do you manage that case? I try to resend message recursively in every 10 sec, but it seems it does not help, because...

All CKAsset is available on all device?

When I save up a CKAsset to server, will it be available on all device? What if on a certain device I do not need one of the asset? Will it take space there too? ...

Move record from development to production in CloudKit?

I have plenty of record manually preloaded to CloudKit but in the development environment. When I deployed development environment, records were not moved into production environment. It is really annoying. Any easy way to move records?...

Hide UIProgressView when animation is completed

I am saving array of records in cloud kit with CKOperation as follows & displaying progress with progress view. let saveOperation = CKModifyRecordsOperation(recordsToSave: ckRecord, recordIDsToDelete: nil) saveOperation.perRecordProgressBlock = { record, progress in if progress >= 1 { self.completedRecord.addObject(record) let totalSavedRecord = Double(self.completedRecord.count) let totalProgress = totalSavedRecord / self.totalStudent let percentageProgress...

Does subscript operator work for CKRecord?

I want to use subscript operator like docs show: myRecord[@"firstName"] = @"Jacob"; but can't get it to work in Swift. Any idea why? ...

Cloudkit , Unrecognized Selector [duplicate]

This question already has an answer here: How can I debug 'unrecognized selector sent to instance' error 5 answers [CKRecord stringForKey:]: unrecognized selector sent to instance 0x17412ece0' I am getting the above error, and not sure what I need to do to correct it. I am running a query...

Collection View Controller crashing and not returning images

I am building a Collection View to return images from a CloudKit database. The results are returning slowly, but they are returning. However, I am getting the classic "fatal error: unexpectedly found nil while unwrapping an Optional value" error and I can't figure out why or what I have to...

Load CKAssets into UICollectionView async

Is there a way to load CKAsset photo into UICollectionView asynchronously ? At the moment, inside queryCompletionHandler from CKDatabase performQuery, I get list of CKRecords with CKAssets, and then set UICollectionView images to CKAsset.fileURL.path, which I then do [UICollectionView reload] The reload takes a long time because it seems like...

NSPredicate case insensitive string search with CloudKit

I'm trying to search a String field of a CloudKit object. The following line successfully compiles and runs without error. NSPredicate(format: "Title BEGINSWITH %@", "Apple") Yet, when I try add case insensitive search, it the app crashes. NSPredicate(format: "Title BEGINSWITH[cdl] %@", "Apple") With error: *** Terminating app due to uncaught...

Copy schema from one container to another

In CloudKit Dashboard, I created Record Types in wrong container (another app). Is there a way to copy or export/import schema to another container (another app)?

CloudKit fetchRecordWithID error: “Fetching asset failed”

I am trying to fetch a record with CloudKit and it fails with the following error: "Fetching asset failed" I confirmed (via the CloudKit Dashboard) that the record exists in my public database and the default zone and the default container (not a custom container). Here is my code: CKContainer...

Some questions about CloudKit

record type: Country(CKRecord) -------------------- name: String code: String -------------------- record type: User(CKRecord) ------------------------ name: String country: CKReference (reference to country record> ------------------------- I have 2 record types (Country and User) created by CloudKit Dashboard. I encountered some cloudkit issues. currently! I query User and then using country reference to fetch...

CloudKit Push Notification, App running on background

When iOS8.2-app is running in the background, it does not receive any push notification, while if it is running on the foreground, it receives the push notifications fine. Any idea what is going on ? Running on CloudKit Development mode, the subscription is for add,edit,and remove, and using the following...

RequestRateLimited in CKQueryOperation

If a CKQueryOperation returns a RequestRateLimited error, should the same queryOperation added to publicDatabase, or should a new queryOperation created based on the cursor received? Does client receive cursor if RequestRateLimited error occurred?

Is user able to delete CKSubscriptions from Settings?

I am curious wether user can deny subscriptions after it was accepted?

Why does CloudKit discovery return zero users on a device but multiple in the simulator?

I have the same address book records on both the simulator and the device but when I run the app I get different results... In the Simulator, Number of records returned = 3 On the Device, Number of records returned = 0 Does discovery even work on device in a...

iOS Swift: Sort array into multidimensional array

I have an array of CKRecords. Each record has startTime and a Name, among other values. What I would like to do is sort the records first by unique startTime and then within each startTime sort by unique Name. The end result would be an array that looks like this...

How to keep data from iCloud(CloudKit) loaded after switching view controllers

I am in the process of making an app using CloudKit, but I have recently run into a problem. In my app, as soon as the main view controller loads, it goes off and fetches data from iCloud. The problem is that when I segue to another view controller and...

CloudKit CKRecordZone

I have been fiddling with CloudKit for some time now, but I can't find a real-life example for how to use CKRecordZone. I understand their capabilities (namely, grouping records, especially for subscriptions), but does someone have a real experience of having used them, and to map which concept ? Thanks...

CloudKit push notification subscription not working

I'm trying to subscribe to push notifications using CloudKit. I'm getting this error: <CKError 0x170c5b1e0: "Unknown Item" (11/2003); server message = "could not find required field fieldID="25"" from this code: let subscription = CKSubscription(recordType: "PlayerData", predicate: NSPredicate(format: "TRUEPREDICATE"), options: CKSubscriptionOptions.FiresOnRecordCreation) let notificationInfo = CKNotificationInfo() notificationInfo.shouldBadge = false subscription.notificationInfo = notificationInfo...

performQuery, cannot set inZoneWithID to nil

Hi I am trying to make a small function that should send me back the record that corresponds to the user by entering his/her name. I created a swift file: import Foundation import CloudKit import UIKit func getGetMainUser(name : String) -> CKRecord { var myRecord : CKRecord! let container =...

Appending an array in swift, having problems

I am getting the error 'AnyObject' does not have a member named 'append' for results that I am trying to post to an array. I'm not sure how to fix the error, as I thought my code was correct. Can someone help me make the proper adjustments? My code is...

cloudkit custom container name

I've downloaded apple's CloudKitAtlas sample code to learn about cloudkit. To run it I have to change the container name. But I wasn't able to do it so far. I cannot use the default's container. And when I click "specify custom containers" and add one, I always get two errors...

“Couldn't send a valid signature” error when using CloudKit

Anyone know what could be causing this error which is returned in the query block below: <CKError 0x7f8d5ba27a10: "Internal Error" (1/4000); "Couldn't send a valid signature"> Here is my code snippet: CKContainer *container = [CKContainer defaultContainer]; CKDatabase *publicDatabase = [container publicCloudDatabase]; //CKDatabase *publicDatabase = [[CKContainer containerWithIdentifier:container] publicCloudDatabase]; NSPredicate *predicate =...

How to organize icloud data by date added?

I am making an app that uses cloud-kit, and when I ask it to return the data saved on it, its out of order. How to i organize the data by date? And then save it in an array, with array [0] as the most recent data added? by the...

Mocking CKContainer for Unit Testing

I am using CloudKit in my application and am trying to mock CKContainer to test my Managers. Here is what i tried: func testAccountStatus() { class MockCloudContainer: CKContainer { override func accountStatusWithCompletionHandler(completionHandler: ((CKAccountStatus, NSError!) -> Void)!) { completionHandler(CKAccountStatus.NoAccount, NSError()) } } let loginManager = LoginManager.sharedInstance let expectation = expectationWithDescription("iCloudStatus") var...

iOS Swift: Crash on deleteRowsAtIndexPaths

I'm getting a crash when I remove a row from a tableView. Not sure what's going on. Here is my code: func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { let items = days[indexPath.row] self.removeItems(items, indexPath: indexPath) } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return days.count...

CloudKit Error when modifying CKRecords: “Zone Busy”

Here's a snippet of code in which I'm modifying some records on a user's private CloudKit DB. let op = CKModifyRecordsOperation(recordsToSave: recordsToModify, recordIDsToDelete: []) op.savePolicy = CKRecordSavePolicy.ChangedKeys op.modifyRecordsCompletionBlock = { saved, deleted, err in println("modified all ... \(saved.count) w err '\(err)' \(err != nil ? err.userInfo : [:])") } self.privateDB.addOperation(op)...

How to check CKAsset changes with CKSubscription?

How do you check whether an image stored with CKAsset has changed in CloudKit? CKNotification doc says about desiredKeys: You can include a maximum of three keys in the array. For the keys you specify, the allowable values are NSString, NSNumber, CLLocation, NSDate, and CKReference. You cannot specify keys whose...

Ensembles with directories in CloudKit

I'm using Ensembles in this project where I have different user-groups stored under separate directories. I've built this more or less copying the example app, Idiomatic's sync-manager. Initialising the CDECloudFileSystem i do this: newSystem = [[CDECloudKitFileSystem alloc] initWithUbiquityContainerIdentifier:[CKContainer defaultContainer].containerIdentifier rootDirectory:directoryString usePublicDatabase:YES]; Where the directoryString is the global ID of the...

Failed to load resource: the server responded with a status of 421 (Bad Request)

I am using Apple's new CloudKit JS reference and sample code to build a simple CRUD app. Before I can even get to CRUD however I am being stopped by Apple authentication. index.html <html> <body> <div id="apple-sign-in-button">Sign in <span id="username"></span> </div> <script> /* * Initialize the global objects we will...

Cannot assign userID as reference

I am trying to assign several different attributes to a record. Date & Name are working properly. Avatar, which is a reference to another record, works also fine. But then I try to assign a reference to the user and I get the slamyourheadagainstthescreen moment. Here is my code: var...

Are there issues with an array of CKAssets in a single CKRecord?

The app I'm writing will let people store several photos, and associate them with a single object. I thought I would use CloudKit, to store these images, as CKAssets. In CloudKit, besides the other property-list types, I can create a CKAsset, and attach a file to it (in my case,...

Estimating and measuring CloudKit database usage

CloudKit has some pretty stringent data limits, restricting to 50MB of database storage plus 1MB per user, with 250KB/day in database bandwidth plus 5KB per user. To find out how CloudKit incorporates database structure and protocol overheads into these numbers, is there a dashboard I'm able to look at to...

How to get recordID of CKReference

I'm using CloudKit and I have two record types. Record type B contains a CKReference to record type A. I'm not having any trouble getting record type B, including the CKReference data of record type A, but I can't figure out how to get the recordID from the CKReference record...

CloudKit (a background process) and UI communication

I have a login screen. The user enters username and password then clicks login. Then the class connects to database loads the data and returns true or false. However, because the perform query operation is done in a different thread, the Load function always returns false. But the debugging shows...

Full CoreData uploading (backup) to iCloud Drive and restore if need

My project is CoreData-based application. Is it enough to upload sqlite-file to CloudDrive for restoring data when need? Is there any tutorials how to implement it?

Anyway to check CloudKit app runs as developer or production mode?

In developer mode I want to skip populating local database from bundle, but I need it when apps run in production mode. Any way to check it?