I want to add a phone number into existing contact. This code working perfectly in iOS8 but not into iOS11. Not getting any errors but while ABNewPersonViewController opens I cannot see new Phone Number.
-(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];
}
Quoting the docs:
The Address Book UI framework is deprecated in iOS 9. Use the APIs defined in the ContactsUI framework instead. To learn more, see ContactsUI .
Maybe you should rewrite this code to the contacts framework to make it work on 11?
One example of this is here: https://www.appsfoundation.com/post/create-edit-contacts-with-ios-9-contacts-ui-framework
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.