问题
CKContainer.discoverAllIdentities(completionHandler:), discoverUserIdentity(recordID: - completion handler returns CKUserIdentity but .lookupInfo is always nil even when contacts contain email, phone, etc. Other properties such as hasiCloudAccount, userRecordID, nameComponents are fine. This issue just started happening with recent Swift 3.1 release. Does anyone know if this is intended behavior as I have not been able to find any reference to CloudKit changes in release notes but this is looking like a privacy thing.
After further investigation, it appears that this issue might be due to the recent iOS 10.3 update. When running the app on an iPhone 5 with 10.2.1 the problem does not occur and lookupInfo properly contains emailAddress
Submitted Apple bug: 31377433
NEW: In addition, if I try to access information via CKDiscoverAllUserIdentitiesOperation, in particular userIdentityDiscoveredBlock -> user.nameComponents the result is "empty string" for apple id's associated with users who are under 12 years old (and potentially on the "Family Sharing" plan). I've found no information about this and apple dev support offered no help either.
回答1:
Since I can´t put a comment because of missing reputation, I have to do it this way...
I also submitted the same bug (31397767) and hope they will fix it.
For CKFetchShareParticipantsOperation
it is necessary to have CKUserIdentityLookupInfo
. Since there is no workaround we need to wait for them to fix it.
I'm just curious about this bug because if you already submitted your app to the app store the whole sharing part would not work for the users.
Update
iOS 10.3.1 update didn't solve the issue.
Update: Solution
I got a response from Apple about this "issue". Here is the answer c&p:
This is the expected behavior, since CKDiscoverAllUserIdentitiesOperation doesn't require prompting the user for Contacts access. If you'd like to turn these results into participants you'll need to request contacts access and get the lookup info off the contacts yourself via the contactIdentifiers property.
// Identities discovered via CKDiscoverAllUserIdentitiesOperation correspond to entries in the local Contacts database. These identities will have contactIdentifiers filled out, which your app may use to get additional information about the contacts that were discovered. Multiple contactIdentifiers may exist for a single discovered user, as multiple contacts may contain the same email addresses or phone numbers.
Note that discovering users and looking up participants are two logically different things- you can only discover users that have made themselves discoverable via -[CKContainer requestApplicationPermission:CKApplicationPermissionUserDiscoverability ...], but you can get a participant for any email address or phone number even if it doesn't correspond to an iCloud account. You don't need to discover users and then turn them into participants- you can just have the user of your app enter addresses for participants to add to a share.
来源:https://stackoverflow.com/questions/43130466/discoverallidentities-discoveruseridentity-returning-nil-for-ckuseridentity-lo