简体   繁体   English

使用iCloud Apple ID匿名登录应用程序

[英]Anonymously Log In to an App with iCloud Apple ID

According to this CloudKit overview : 根据CloudKit概述

CloudKit also enables your users to anonymously sign in to your apps with their iCloud Apple IDs without sharing their personal information. CloudKit还允许您的用户使用他们的iCloud Apple ID匿名登录您的应用,而无需共享他们的个人信息。

I can't find anything else in their documentation about this capability. 我在他们的文档中找不到关于此功能的任何其他内容。 I already have an app with my own backend, so I wouldn't need any of the back-end-as-a-service features that CloudKit offers, but I would like to take advantage of logging a user in with their iCloud account, much the same way we currently do with Facebook and Twitter. 我已经有了一个带有我自己后端的应用程序,因此我不需要任何CloudKit提供的后端即服务功能,但我想利用用户登录iCloud帐户,与我们目前使用Facebook和Twitter的方式大致相同。

Is that possible with CloudKit, or do you also have to leverage their BAAS features in order to take advantage of login? 是否可以使用CloudKit,或者您是否还必须利用其BAAS功能才能利用登录?

From what they discussed at WWDC, you'd do this using the fetchUserRecordIDWithCompletionHandler: method on CKContainer . 从他们在WWDC讨论了什么问题,你可以这样做使用fetchUserRecordIDWithCompletionHandler:上法CKContainer That returns a CKRecordID that corresponds to the current user. 返回与当前用户对应的CKRecordID This ID will be stable across devices but different for each app-- so if the same person uses your app on multiple devices, your app will get the same result everywhere, but other apps would get different results from yours. 此ID在各个设备上都是稳定的,但每个应用都有所不同 - 因此,如果同一个人在多个设备上使用您的应用,您的应用会在任何地方获得相同的结果,但其他应用会从您的应用获得不同的结果。

Once you have the CKRecordID you can look up limited other user data (their name and email, I think) using fetchRecordWithID:completionHandler: . 一旦你有CKRecordID你可以使用CKRecordID查找有限的其他用户数据(他们的名字和电子邮件) fetchRecordWithID:completionHandler: . This request will trigger a permission alert to the user, so you only get it if they allow it. 此请求将触发用户的权限警报,因此只有在允许的情况下才能获取该请求。

This doesn't require you to use anything else in CloudKit. 这不要求您在CloudKit中使用任何其他内容。 It does require that the user actually have an iCloud account configured on the device. 它确实要求用户实际在设备上配置了iCloud帐户。

The permission alert will only pop if you call -[CKContainer requestApplicationPermission:CKApplicationPermissionUserDiscoverability...] . 只有在调用-[CKContainer requestApplicationPermission:CKApplicationPermissionUserDiscoverability...]时才会弹出权限警报。

If the user grants permission ( CKApplicationPermissionStatusGranted ) then you can get the user's first and last name by running a CKDiscoverUserInfosOperation . 如果用户授予权限( CKApplicationPermissionStatusGranted ),则可以通过运行CKDiscoverUserInfosOperation获取用户的名字和姓氏。

Requesting discoverability means that you can see the user's first and last name, and that any other user of the container can find their user record ID via an email address or look up their first and last name via a user record ID. 请求可发现性意味着您可以看到用户的名字和姓氏,并且容器的任何其他用户都可以通过电子邮件地址找到他们的用户记录ID,或通过用户记录ID查找他们的姓名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM