This iOS app written in Swift provides code samples of some of the core API methods of the CloudKit Framework. Topics covered:
- Requesting discoverability permission and retrieving users' discoverable information.
- Querying records.
- CRUD operations on zones.
- CRUD operations on records.
- Fetching and paginating through changed records in a zone using CloudKit's syncing capabilities.
- CRUD operations on subscriptions.
- Registering for notifications and marking them as read.
Before running the sample app you must change the bundle identifier in the General tab of your project settings to a container identifier that you own. The app requires a record type Items with the following fields.
- name : String
- location : Location
- asset : Asset
Create this record type through CloudKit Dashboard if it doesn't already exist. You can also create a couple of public records through the dashboard and then view them in the Query section of the app.
Whether you are running the app on a simulator or a device, you must be signed in to iCloud to use the CloudKit API methods other than the query sample which doesn't require authentication.
You must run the app on a device to test CloudKit notifications. You will be prompted to give the app permission to receive remote notifications on startup. Then, to test notifications, create a zone-level (for instance) subscription and write records to that zone using the javascript sample (pointing to the same container - see the corresponding instructions). You will not be notified of record changes if those changes are made from the same device, so you must either use another device or the javascript sample. When you have been notified of a change to a zone, you can run the FetchRecordChanges operation on that zone to get the changed records. This is covered by the Sync section of the app.
Copyright (C) 2015 Apple Inc. All rights reserved.