gpt4 book ai didi

xcode - 使用 ABPeoplePickerNavigationControllerDelegate 从 ABRecord 获取联系人姓名或图像等数据

转载 作者:行者123 更新时间:2023-11-28 13:07:24 24 4
gpt4 key购买 nike

我想让我的应用程序的用户能够从他们的地址簿中获取他们的联系人。我可以展示 ABPeoplePickerNavigationController,用户可以选择一个人,然后 ABPPNC 再次关闭。

这就是我用来展示它的代码:

    let peopleController = ABPeoplePickerNavigationController()
peopleController.delegate = self
peopleController.predicateForSelectionOfPerson = NSPredicate(value: true)
self.presentViewController(peopleController, animated: true, completion: nil)

并且调用了 peoplePickerNavigationController didSelectPerson 函数,但我不知道如何从 ABRecord 类型的人那里获取信息。在 https://developer.apple.com/library/ios/documentation/AddressBookUI/Reference/ABPeoplePickerNavigationController_Class/index.html#//apple_ref/doc/constant_group/Address_Book_Properties Apple 说有一些地址簿属性,例如:ABPersonNamePrefixProperty 或 ABPersonMiddleNameProperty,但我不知道如何使用它。

所以基本上我想做这样的事情:

func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!) {

// What I want to do:
let name = person.lastName
let firstName = person.firstName
let image = person.image
}

最佳答案

经过长时间的搜索,我找到了适合我的答案:

    func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!) {

var firstName: String?
if ABRecordCopyValue(person, kABPersonFirstNameProperty) != nil{
firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty).takeRetainedValue() as? String
}
var lastName: String?
if ABRecordCopyValue(person, kABPersonLastNameProperty){
lastName = ABRecordCopyValue(person, kABPersonLastNameProperty).takeRetainedValue() as? String
}

var pImage: UIImage?
if person != nil && ABPersonHasImageData(person){
pImage = UIImage(data: ABPersonCopyImageData(person).takeRetainedValue())

}


}

关于xcode - 使用 ABPeoplePickerNavigationControllerDelegate 从 ABRecord 获取联系人姓名或图像等数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32329265/

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