[英]Verify if user has account in my app with iCloud auth approach
I have just read an article where it was explained how to get the token from iCloud in order to execute authentication with the iOS platform. 我刚刚读了一篇文章,其中解释了如何从iCloud获取令牌以执行iOS平台的身份验证。
How can we combine Android and iOS with such an approach? 我们如何将Android和iOS与这种方法结合起来?
How Android will know that user has iOS account? Android如何知道该用户拥有iOS帐户?
Which kind of credentials do I need to ask users to verify if they already have an account on the iOS platform? 我需要问哪种凭证来验证用户是否已在iOS平台上拥有帐户?
Aleksey, 阿列克西
This code, confirms somebody is logged into iCloud by trying to access an iCloudKit container. 此代码通过尝试访问iCloudKit容器来确认有人登录到iCloud。 The first method checks and sends a notification if it if it fails, the second method trigger by said failure shunts the user to the control panel so they can sign into 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)")
}
})
}
In your view Controller... 在您看来控制器...
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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.