Not working add number to existing contacts in ios 11

178 Views Asked by At

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];
}
1

There are 1 best solutions below

2
battlmonstr On

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