A simple flutter plugin for interactions with Apple Cloud Kit API on iOS devices.
Currently, the following functionality is supported:
- getAccountStatus - getting status of the user account;
- saveRecord - saving records;
- getRecord - getting records by key;
- getRecordsByType - getting records by type;
- deleteRecord - deleting record by key.
FlutterCloudKit cloudKit = FlutterCloudKit(containerId: exampleContainerId);
containerId
parameter is optional. When not provided, the default container will be used.
CloudKitAccountStatus accountStatus = await cloudKit.getAccountStatus();
await cloudKit.saveRecord(scope: CloudKitDatabaseScope.private, recordType: exampleRecordType, record: {'fieldName': 'fieldValue'}, recordName: 'RecordName');
CloudKitRecord record = await cloudKit.getRecord(scope: CloudKitDatabaseScope.private, recordName: 'RecordName');
List<CloudKitRecord> records = await cloudKit.getRecordsByType(scope: CloudKitDatabaseScope.private, recordType: exampleRecordType);
await cloudKit.deleteRecord(scope: CloudKitDatabaseScope.private, recordName: 'RecordName');
See Enabling CloudKit in Your App.
Basically, before you start using the plugin, you need to:
- Add the iCloud Capability to Your Xcode Project;
- Create a container you're going to use in Xcode;
- Select the CloudKit checkbox;
- Check the box next to the container name;
Also, in order to be able to retrieve records by type, you will need to add some indexes to the CloudKit database.
See Enable Querying for Your Record Type.
For every new record type you'll need to do the following:
- Create the first record of this type;
- Go to the CloudKit Console;
- Select your database;
- Go to the Indexes;
- Select your record type;
- Click Add Basic Index and create two indexes:
FIELD
:recordName
andIndex Type
:QUERYABLE
(needed to fetch records);FIELD
:createdTimestamp
andIndex Type
:SORTABLE
(needed to sort them by creation time).
- Click Save Changes