CloudKit通过电子邮件发现用户

时间:2016-08-10 16:39:19

标签: ios swift cloudkit nsoperation ckoperation

我正在使用下面的CKOperation通过电子邮件查找用户记录。每次我运行代码时,它总是返回发现为nil的用户。我知道电子邮件地址是正确的。你知道我可能在哪里出错或者CloudKit是否有错误?

谢谢

let operation = CKDiscoverUserInfosOperation()

        operation.qualityOfService = .UserInitiated
        operation.emailAddresses = ["email@me.com"]

        operation.discoverUserInfosCompletionBlock = { [unowned self] (userInfoString, userInfoID, error) in
            if error != nil {
                dispatch_async(dispatch_get_main_queue()) {
                    //Update UI Here
                    let alert = UIAlertView(title: "Error", message: "Unable to fetch data. Please try again later.", delegate: self, cancelButtonTitle: "Okay").show()
                }
            } else {
                print("Info string: \(userInfoString)")
                print("Info: \(userInfoID)")
            }
        }

        container.addOperation(operation)

我还在viewDidLoad

中添加了此内容
CKContainer.defaultContainer().requestApplicationPermission(CKApplicationPermissions.UserDiscoverability,
                                                                completionHandler: {
                                                                    applicationPermissionStatus, error in
    })

0 个答案:

没有答案