我想点击按钮打开Apple的内置联系人书。 我尝试了其他一些代码,但它没有用。 我在我的项目中添加了4个库。
答案 0 :(得分:1)
您可以使用以下方式访问地址簿:
首先导入#import <AddressBookUI/AddressBookUI.h>
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentViewController:picker animated:YES completion:nil];
# pragma mark - peoplePickerDelegate methods
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
[self displayPerson:person];
[self dismissViewControllerAnimated:YES completion:nil];
return NO;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
return NO;
}
- (void)displayPerson:(ABRecordRef)person
{
NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString* phone = nil;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,
kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0) {
phone = (__bridge_transfer NSString*)
ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
} else {
phone = @"[None]";
}
CFRelease(phoneNumbers);
}
它可能对你有帮助......
答案 1 :(得分:1)
请尝试使用此代码打开默认联系人列表,并通过其委托方法管理此列表:
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.predicateForEnablingPerson = [NSPredicate predicateWithFormat:@"%K.@count > 0", ABPersonPhoneNumbersProperty];
[self.navigationController presentViewController:picker animated:YES completion:nil];
不要忘记在视图控制器中导入地址簿框架及其代理。
#import <AddressBookUI/AddressBookUI.h>
#import <AddressBook/AddressBook.h>
代表:
ABPeoplePickerNavigationControllerDelegate
答案 2 :(得分:0)