验证用户是否在我的应用中使用ICLOUD AUTH方法的帐户



我刚刚阅读了一篇文章,其中解释了如何从iCloud中获取令牌,以便使用iOS平台执行身份验证。

我们如何将Android和iOS与这种方法相结合?

Android如何知道用户拥有iOS帐户?

我需要要求用户验证他们是否已经在iOS平台上有帐户?

Aleksey,

此代码,通过尝试访问iCloudkit容器来确认某人已登录iCloud。第一种方法检查并发送通知,如果该通知失败,则通过所述故障分流用户进入控制面板,因此他们可以登录iCloud。

 func isAuthorized4Cloud() {
    container = CKContainer(identifier: "iCloud.X")
    publicDB = container.publicCloudDatabase
    privateDB = container.privateCloudDatabase
    var userID: CKRecordID!
    container.fetchUserRecordID( completionHandler: { recordID, error in
        if error == nil {
            userID = recordID
            print("files_setup userID (userID.recordName)")
            NotificationCenter.default.post(name: Notification.Name("cloudConnected"), object: nil, userInfo: nil)
        } else {
            NotificationCenter.default.post(name: Notification.Name("noCloud"), object: nil, userInfo: nil)
            print("files_setup (error?.localizedDescription)")
        }
    })
}

在您的视图控制器中...

  NotificationCenter.default.addObserver(self, selector: #selector(noCloud), name: Notification.Name("noCloud"), object: nil)
  func noCloud(notification:NSNotification) {
    DispatchQueue.main.async {
        self.navigation.isHidden = true
        let alert = UIAlertController(title: "Stop", message: "Sorry, you need to log into iCloud ...", preferredStyle: UIAlertControllerStyle.alert)
        let settingsAction = UIAlertAction(title: "Settings", style: .default) { (_) -> Void in
            guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
                return
            }
            if UIApplication.shared.canOpenURL(settingsUrl) {
                UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
                    print("Settings opened: (success)") // Prints true
                })
            }
        }
        alert.addAction(settingsAction)
        let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil)
        alert.addAction(cancelAction)
        self.present(alert, animated: true, completion: nil)
    }
}

最新更新