Skip to content

edorphy/CloudKitWebServices

Repository files navigation

CloudKit Web Services

This package enables developers to write code that interacts with CloudKit in targets that don't support the CloudKit Framework directly (such as App Clips).

Stability

This project is currently undergoing development and is subject to breaking changes. During this development Semantic Versioning will not be followed entirely as long as the package remains under release version 1.0.0.

Develop Branch Status: Swift

Contributing

The goal of this project is to provide developers with easy access to CloudKit where it is not available such as within App Clips. If you find something missing that you'd like to see get added, open up an issue, or if you're comfortable writing framework code, open up a Pull Request.

Requirements

  • An Apple Developer account with access to the CloudKit Console
  • iOS 15.0 or newer

Getting Started

This package is designed to mirror Apple's CloudKit framework when possible. This will allow the library to be a drop-in replacement for the native CloudKit client when it isn't available.

To get started with CloudKit Web Services, first create a CKContainer.


// Configuration

import CloudKitWebServices

let identifier = "iCloud.{your-container-name}"
let token = "{your-token-generated-from-cloudkit-console}"

let container = CKContainer(identifier: identifier, token: token, environment: .development)

Creating a query request


// Create an operation that queries all records of the "ExampleType"
let queryOperation = CKQueryOperation(query: CKQuery(recordType: "ExampleType"))

queryOperation.recordMatchedBlock = { recordID, result in 
  switch result {
  case .success(let record):
    // TODO: Do something with the record that was received.
    break
    
  case .failure(let error):
    // TODO: Handle per-record failure, perhaps retry fetching it manually in case an asset failed to download or something like that.
    break
}

queryOperation.queryResultBlock = { result in 
  switch result {
  case .success:
    // TODO: Yay, the operation was successful, now do something. Perhaps reload your awesome UI.
    break
    
  case .failure(let error):
    // TODO: An error happened at the operation level, check the error and decide what to do. Retry might be applicable, or tell the user to connect to internet, etc..
    break
}

container.publicCloudDatabase.add(queryOperation)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages