Closed PPacie closed 7 years ago
I have just released version 3.2.0 with support for the new iOS 10 functions. The function discoverUserInfo will now return an AnyObject. Depending on the iOS version it will be a CKUserIdentity or a CKDiscoverdUserInfo. You can handle that with code like this:
func showNameFor(_ contact: AnyObject) -> String {
if #available(iOS 10.0, *) {
return showNameFor10(contact as! CKUserIdentity)
} else {
return showNameFor9(contact as! CKDiscoveredUserInfo)
}
}
@available(iOS 10.0, *)
func showNameFor10(_ contact: CKUserIdentity) -> String {
let nickname = contact.nameComponents?.nickname ?? ""
let givenName = contact.nameComponents?.givenName ?? ""
let familyName = contact.nameComponents?.familyName ?? ""
let nameSuffix = contact.nameComponents?.nameSuffix ?? ""
let middleName = contact.nameComponents?.middleName ?? ""
let namePrefix = contact.nameComponents?.namePrefix ?? ""
let emailAddress = contact.lookupInfo?.emailAddress ?? ""
let phoneNumber = contact.lookupInfo?.phoneNumber ?? ""
let name = "\(nickname) - \(givenName) \(middleName) \(namePrefix) \(familyName) \(nameSuffix) - \(emailAddress) \(phoneNumber))" // contact.userRecordID?.recordName
return name.replacingOccurrences(of: " ", with: " ").replacingOccurrences(of: " ", with: " ")
}
func showNameFor9(_ contact: CKDiscoveredUserInfo) -> String {
var firstName: String = ""
var lastName: String = ""
if #available(iOS 9.0, *) {
firstName = contact.displayContact?.givenName ?? ""
lastName = contact.displayContact?.familyName ?? ""
} else {
firstName = contact.firstName ?? ""
lastName = contact.lastName ?? ""
}
return "\(firstName) \(lastName)"
}
Hi Edwin,
Yes, it seems that deprecation was the issue. Thank you very much.
Cheers.
I received the following message when opening the app:
[37816:950132] [LogFacilityCK] Got a user discovery progress callback with no record id: { UserIdentity = "<CKUserIdentity: 0x6100000acf60; lookupInfo=<CKUserIdentityLookupInfo: 0x610000265dc0; email=xxxxx@gmail.com>, cached=0, nameComponents=Pablo, userID=<CKRecordID: 0x6100002217e0; recordName=_a29465019ed7e273fd544e39e6c73232, zoneID=_defaultZone:defaultOwner>>"; } [37816:.] RightMenuViewController.swift(45) loadContacts: AllContactUserInfo count = Optional(0)
The same "Got a user...." message is being displayed for the 3 contactas I have using the app.
I think it can be an Apple issue related with the deprecation of
CKDiscoveredUserInfo
which is being replaced byCKUserIdentity
(and its methods:discoverAllIdentitiesWithCompletionHandler
, etc.) in iOS 10 as I tested it on iOS 9 and it worked alright.