swift Swift - CloudKit - 提醒用户输入iCloud凭据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift Swift - CloudKit - 提醒用户输入iCloud凭据相关的知识,希望对你有一定的参考价值。

See: https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/CloudKitQuickStart/CreatingaSchemabySavingRecords/CreatingaSchemabySavingRecords.html

Improve the user’s experience by verifying that the user is signed in to their iCloud account 
before saving records. If the user is not signed in, present an alert instructing the user how 
to enter their iCloud credentials and enable iCloud Drive. 

Insert your code that saves records in the else clause below.

CKContainer.default().accountStatus(completionHandler: {(_ accountStatus: CKAccountStatus, _ error: Error?) -> Void in
    if accountStatus == .noAccount {
        var alert = UIAlertController(title: "Sign in to iCloud", message: "Sign in to your iCloud account to write records. On the Home screen, launch Settings, tap iCloud, and enter your Apple ID. Turn iCloud Drive on. If you don't have an iCloud account, tap Create a new Apple ID.", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "Okay", style: .cancel, handler: nil))
        self.present(alert, animated: true) { _ in }
    }
    else {
        // Insert your just-in-time schema code here
    }
})

以上是关于swift Swift - CloudKit - 提醒用户输入iCloud凭据的主要内容,如果未能解决你的问题,请参考以下文章

swift Swift - CloudKit - 获取用户ID

swift Swift - CloudKit - 推送通知

swift Swift - CloudKit共享

swift Swift - CloudKit - 维护本地缓存

swift Swift - CloudKit - 部署架构

swift Swift - CloudKit订阅 - 5