2
votes

My app allows the users to import contacts from their address book and store them in our CardDAV server. I'd like keep the contacts on our CardDAV server with all other linked contacts in the address book (iCloud for example) in sync.

When a contact is edited using the address book's unified contact view, all linked contacts are updated. I'd like to allow my app's users to do the same without leaving the app. Does ABPersonViewController have the same functionality as the native iOS address book to update all linked contacts using the "unified view"?

The controller has a property called shouldShowLinkedPeople, but I'm not certain what it actually does.

1

1 Answers

1
votes

I was actually having the same exact issue and couldn't find the answer. But then I saw that you mentioned the property "shouldShowLinkedPeople" and that is exactly the solution! All you have to do is set the property to YES and you will be able to view and edit all linked contacts in your ABPersonViewController.

Here's what I did (my app takes advantage of ABPeoplePickerNavigationController):

In my subclass of ABPeoplePickerNavigationController which conforms to the ABPeoplePickerNavigationControllerDelegate:

#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

@interface ContactsViewController : ABPeoplePickerNavigationController <ABPeoplePickerNavigationControllerDelegate>

@end

Implement the method, which allows you to view/edit a contact via ABPersonViewController by clicking on a contact in ABPeoplePickerNavigationController:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
    ABPersonViewController *contactDetailViewController = [[ABPersonViewController alloc] init];
    contactDetailViewController.shouldShowLinkedPeople = YES;
    contactDetailViewController.displayedPerson = person;
    contactDetailViewController.allowsEditing = YES;

    [self pushViewController:contactDetailViewController
                    animated:YES];

    return NO;
}

To edit a contact that is linked (for example to Facebook, iCloud, etc), you must include the line:

contactDetailViewController.shouldShowLinkedPeople = YES;

Otherwise you'll only be able to edit one of the linked contacts, which can be undesired.