gpt4 book ai didi

abaddressbook - 在 iOS9 CloudKit/ABPerson (ABAddressBook) 中查找用户名或名字/姓氏

转载 作者:行者123 更新时间:2023-12-04 06:26:05 25 4
gpt4 key购买 nike

iOS9 弃用用户信息功能 for CloudKitABPerson .

例如在 CKDiscoveredUserInfo 的属性中

firstName" Deprecated in iOS 9.0

lastName" Deprecated in iOS 9.0



我想要以前在 iOS8 CloudKit 中提供的姓氏和名字。

如何在 iOS9 CloudKit、ABPerson 或其他东西中检索类似信息?

Short of grace method is this
[[UIDevice currentDevice] name]; 

NSArray *nameArray = [[NSHost currentHost] names];
NSString *user = [nameArray objectAtIndex:0];

两者都打印例如约翰的 iPhone。

最佳答案

对于iOS9,通过Contact Framework获取用户个人联系方式

The Contacts framework provides an Objective-C and Swift API to access the user’s contact information.



替换 ABAdressBook

This framework is available on all Apple platforms and replaces the Address Book framework in iOS and OS X.



具体来说, CNContact

The CNContact is a thread-safe class that represents an immutable value object for contact properties, such as the first name and phone numbers of a contact.



获取联系人

You can fetch contacts using the contact store (CNContactStore), which represents the user's contacts database



搜索用户的联系人数据库 (iOS 9.0 新增)

例如,名字、姓氏、生日、电话号码等。
let store = CNContactStore()
let contacts = try store.unifiedContactsMatchingPredicate(CNContact.predicateForContactsMatchingName("Appleseed"), keysToFetch:[CNContactGivenNameKey, CNContactFamilyNameKey])

let contact = contacts!.first //assuming contain at least one contact

// Checking if phone number is available for the given contact.
if (contact.isKeyAvailable(CNContactPhoneNumbersKey)) {
print("\(contact.givenName) \(contact.familyName)")
} else {
//Refetch the keys
let keysToFetch = [CNContactGivenNameKey, CNContactFamilyNameKey]
let refetchedContact = try store.unifiedContactWithIdentifier(contact.identifier, keysToFetch: keysToFetch)
print("\(refetchedContact.givenName) \(refetchedContact.familyName)")
}

搜索当前用户信息
if let personInfo:CNContact = CKDiscoveredUserInfo.displayContact{

println("first name: \(personInfo.givenName) last name: \(personInfo.familyName) ") }

关于abaddressbook - 在 iOS9 CloudKit/ABPerson (ABAddressBook) 中查找用户名或名字/姓氏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30726681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com