Fuelet / flutter_cloud_kit

A simple flutter plugin for interactions with Apple Cloud Kit API on iOS devices
MIT License
42 stars 18 forks source link

flutter_cloud_kit

A simple flutter plugin for interactions with Apple Cloud Kit API on iOS devices.

Currently, the following functionality is supported:

Usage

Creating an instance of the FlutterCloudKit class

FlutterCloudKit cloudKit = FlutterCloudKit(containerId: exampleContainerId);

containerId parameter is optional. When not provided, the default container will be used.

Getting account status

CloudKitAccountStatus accountStatus = await cloudKit.getAccountStatus();

Saving a record

await cloudKit.saveRecord(scope: CloudKitDatabaseScope.private, recordType: exampleRecordType, record: {'fieldName': 'fieldValue'}, recordName: 'RecordName');

Getting a record

CloudKitRecord record = await cloudKit.getRecord(scope: CloudKitDatabaseScope.private, recordName: 'RecordName');

Getting records by type

List<CloudKitRecord> records = await cloudKit.getRecordsByType(scope: CloudKitDatabaseScope.private, recordType: exampleRecordType);

Deleting a record

await cloudKit.deleteRecord(scope: CloudKitDatabaseScope.private, recordName: 'RecordName');

Setup

See Enabling CloudKit in Your App.

Basically, before you start using the plugin, you need to:

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:

  1. Create the first record of this type;
  2. Go to the CloudKit Console;
  3. Select your database;
  4. Go to the Indexes;
  5. Select your record type;
  6. Click Add Basic Index and create two indexes:
    • FIELD: recordName and Index Type: QUERYABLE (needed to fetch records);
    • FIELD: createdTimestamp and Index Type: SORTABLE (needed to sort them by creation time).
  7. Click Save Changes