IOS 调用通讯录获取联系人 报错:plugin com.apple.MobileAddressBook.ContactsViewService invalid
报错: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];
}];
}