ios - 如何在保存数据之前检查用户是否登录到 iCloud

标签 ios icloud cloudkit

在将数据保存到 CloudKit 之前,如何检查用户是否有帐户并已登录?

最佳答案

您需要使用 CKContainer 类中的 accountStatusWithCompletionHandler 并检查返回的 accountStatus

这在 CloudKit Quick Start 中有描述文档。

这是示例的 Swift 版本:

    CKContainer.defaultContainer().accountStatusWithCompletionHandler { accountStatus, error in
        if accountStatus == .NoAccount {
            let 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: "OK", style: .Default, handler: nil))
            self.presentViewController(alert, animated: true, completion: nil)
        } else {
            // Code if user has account here...
        }
    }

关于ios - 如何在保存数据之前检查用户是否登录到 iCloud,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39060513/

相关文章:

ios - 如何通过删除和重新安装应用程序来持久化 Core Data 中的数据

ios - 'iCloud' 功能仅适用于注册 Apple Developer Program 的用户。请访问 https ://developer. apple.com/programs/报名

android - 标题项的 iOS 设备右浮动问题

ios - Flutter 'Error running pod install' 'Pods-Runner' 目标具有传递依赖

ios - (const) 变量的范围未定义为 extern 或 static

ios - CloudKit iOS 9.0 didReceiveRemoteNotification 在 iOS 9.3 发布后未调用

ios - 如何解决设备之间的 CloudKit 功能不一致

android - AWS MobileHub : Rename Android/iOS sample project

iphone - 如何测试从 iCloud 备份恢复开发中的 iOS 应用程序?

ios - 客户端oplock错误,在CloudKit中保存记录