ABAddressBookGetPersonWithRecordID returns 空
ABAddressBookGetPersonWithRecordID returns NULL
在我的应用程序中,我从联系人中选择 phone 号码。
我需要存储记录 ID,然后检索 recordref。
为了测试逻辑,我尝试了以下示例
在下面的委托中,我获取了此人的记录 ID。
然后尝试检索 Recordref。
记录器 (gref) 为空
请让我知道我做错了什么。
我已经在 iPhone 6 和 os 8.2
上测试过这个
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person
{
ABRecordID sid = ABRecordGetRecordID(person);
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef gref = ABAddressBookGetPersonWithRecordID(addressBook, sid);
NSLog(@“org record ref %@",person);
NSLog(@“new record ref %@",gref);
}
在使用通讯录之前,我们需要获得访问通讯录的权限。
例子
CFErrorRef myError = NULL;
ABAddressBookRef myAddressBook = ABAddressBookCreateWithOptions(NULL, &myError);
__block ABRecordRef gref;
ABAddressBookRequestAccessWithCompletion(myAddressBook,
^(bool granted, CFErrorRef error) {
if (granted) {
gref = ABAddressBookGetPersonWithRecordID(myAddressBook, sid);
NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(gref));
NSLog(@"after record ref %@",gref);
NSLog(@"human name %@",contactName);
} else {
// Handle the case of being denied access and/or the error.
}
CFRelease(myAddressBook);
});
在我的应用程序中,我从联系人中选择 phone 号码。 我需要存储记录 ID,然后检索 recordref。 为了测试逻辑,我尝试了以下示例 在下面的委托中,我获取了此人的记录 ID。 然后尝试检索 Recordref。 记录器 (gref) 为空 请让我知道我做错了什么。 我已经在 iPhone 6 和 os 8.2
上测试过这个- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person
{
ABRecordID sid = ABRecordGetRecordID(person);
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef gref = ABAddressBookGetPersonWithRecordID(addressBook, sid);
NSLog(@“org record ref %@",person);
NSLog(@“new record ref %@",gref);
}
在使用通讯录之前,我们需要获得访问通讯录的权限。 例子
CFErrorRef myError = NULL;
ABAddressBookRef myAddressBook = ABAddressBookCreateWithOptions(NULL, &myError);
__block ABRecordRef gref;
ABAddressBookRequestAccessWithCompletion(myAddressBook,
^(bool granted, CFErrorRef error) {
if (granted) {
gref = ABAddressBookGetPersonWithRecordID(myAddressBook, sid);
NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(gref));
NSLog(@"after record ref %@",gref);
NSLog(@"human name %@",contactName);
} else {
// Handle the case of being denied access and/or the error.
}
CFRelease(myAddressBook);
});