我想将电话号码添加到现有联系人中。此代码在 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];
}
最佳答案
引用文档:
The Address Book UI framework is deprecated in iOS 9. Use the APIs defined in the ContactsUI framework instead. To learn more, see ContactsUI.
也许您应该将此代码重写到联系人框架中以使其在 11 上运行?
这里有一个例子: https://www.appsfoundation.com/post/create-edit-contacts-with-ios-9-contacts-ui-framework
关于ios - 无法将号码添加到 ios 11 中的现有联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49231102/