swift Swift - CloudKit - 创建自定义区域

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift Swift - CloudKit - 创建自定义区域相关的知识,希望对你有一定的参考价值。

See: https://www.whatmatrix.com/blog/a-guide-to-cloudkit-how-to-sync-user-data-across-ios-devices/

Since this is a first example of using an operation, here are a couple of general observations:

First, all CloudKit operations have custom completion closures (and many have intermediate closures, 
depending on the operation). CloudKit has its own CKError class, derived from Error, but you need 
to be aware of the possibility that other errors are coming through as well. Finally, one of the 
most important aspects of any operation is the qualityOfService value. Due to network latency, 
airplane mode, and such, CloudKit will internally handle retries and such for operations at a 
qualityOfService of “utility” or lower. Depending on the context, you may wish to assign a higher 
qualityOfService and handle these situations yourself.

Once set up, operations are passed to the CKDatabase object, where they’ll be executed on a 
background thread.

// Create a custom zone to contain our note records. We only have to do this once.
private func createZone(completion: @escaping (Error?) -> Void) {
	let recordZone = CKRecordZone(zoneID: self.zoneID!)
	let operation = CKModifyRecordZonesOperation(recordZonesToSave: [recordZone], recordZoneIDsToDelete: [])
	operation.modifyRecordZonesCompletionBlock = { _, _, error in
		guard error == nil else {
			completion(error)
			return
		}
		completion(nil)
	}
	operation.qualityOfService = .utility
	let container = CKContainer.default()
	let db = container.privateCloudDatabase
	db.add(operation)
}

以上是关于swift Swift - CloudKit - 创建自定义区域的主要内容,如果未能解决你的问题,请参考以下文章

swift Swift - CloudKit - 获取用户ID

swift Swift - CloudKit - 推送通知

swift Swift - CloudKit共享

swift Swift - CloudKit - 维护本地缓存

swift Swift - CloudKit - 部署架构

swift Swift - CloudKit订阅 - 5