IOS 调用通讯录获取联系人 报错:plugin com.apple.MobileAddressBook.ContactsViewService invalid

liu539917729 2016-06-13 10:26:35
报错:plugin com.apple.MobileAddressBook.ContactsViewService invalidated
有没有遇到过的,怎么解决?

代码如下:
#pragma mark 从通讯录读取联系人信息
- (IBAction)readContacts {
[self accessTheAddress]; //授权
ABPeoplePickerNavigationController *nav = [[ABPeoplePickerNavigationController alloc] init];
nav.peoplePickerDelegate = self;
if([[UIDevice currentDevice].systemVersion floatValue]>=8.0){
nav.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:false];
}
[self presentViewController:nav animated:YES completion:nil];
}
//获取读取电话本权限//由于在ios6以后对用户信息提供了安全的保护,在获取前必须要通过用户的同意才行
- (void)accessTheAddress{
ABAddressBookRef addressBook = nil;

if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
//等待同意后向下执行
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
dispatch_semaphore_signal(sema);
// NSLog(@"这里是用户选择是否允许后的执行代码");
});
}
else{
addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
}

}
#pragma mark -- ABPeoplePickerNavigationControllerDelegate
//取消选择
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
[peoplePicker dismissViewControllerAnimated:YES completion:nil];
}
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person{
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
personViewController.displayedPerson = person;
[peoplePicker pushViewController:personViewController animated:YES];
}
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
ABMultiValueRef valuesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
CFIndex index = ABMultiValueGetIndexForIdentifier(valuesRef,identifier);
//电话号码
CFStringRef telValue = ABMultiValueCopyValueAtIndex(valuesRef,index);
//name
CFStringRef anFullName = ABRecordCopyCompositeName(person);
[self dismissViewControllerAnimated:YES completion:^{
self.phone.text = (__bridge NSString *)telValue;
self.name.text = [NSString stringWithFormat:@"%@",anFullName];
}];

}

...全文
458 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
网易云捕 2016-06-13
  • 打赏
  • 举报
回复
如果你是在iOS 9 以后的系统用的话,应该有问题。参考:https://developer.apple.com/library/ios/documentation/AddressBookUI/Reference/ABPeoplePickerNavigationController_Class/
liu539917729 2016-06-13
  • 打赏
  • 举报
回复
引用 1 楼 crash163 的回复:
如果你是在iOS 9 以后的系统用的话,应该有问题。参考:https://developer.apple.com/library/ios/documentation/AddressBookUI/Reference/ABPeoplePickerNavigationController_Class/
最新的Xcode。应用的版本是IOS8.0的,功能上没有问题只是会有这个输出:plugin com.apple.MobileAddressBook.ContactsViewService invalidated,想搞明白原因。

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧