我想在现有联系人中添加电话号码。此代码在iOS8中完美运行,但在iOS11中无法运行。没有得到任何错误但是当ABNewPersonViewController打开时我看不到新的电话号码。
-(void)addToExstingContact{
ABPeoplePickerNavigationController *personPicker = [[ABPeoplePickerNavigationController alloc] init];
personPicker.peoplePickerDelegate = self;
[self presentViewController:personPicker animated:true completion:nil];
}
-(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person{
[peoplePicker dismissViewControllerAnimated:true completion:^{
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutableCopy(phoneNumbers);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue, (__bridge CFTypeRef)(newPhoneNumber), kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil);
CFRelease(phoneNumberMultiValue);
ABNewPersonViewController *view = [[ABNewPersonViewController alloc] init];
view.newPersonViewDelegate = self;
view.displayedPerson = person;
UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:view];
[self presentViewController:newNavigationController animated:true completion:nil];
}];
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
[peoplePicker dismissViewControllerAnimated:true completion:nil];
}
答案 0 :(得分:2)
引用文档:
在iOS 9中不推荐使用通讯簿UI框架。使用API 而是在ContactsUI框架中定义。要了解更多信息,请参阅 ContactsUI
也许您应该将此代码重写到联系人框架以使其在11上工作?
这方面的一个例子是: https://www.appsfoundation.com/post/create-edit-contacts-with-ios-9-contacts-ui-framework