4

Let me explain what i want to do first. In native Iphone in the Recents tab if you click on a contact not found in any addressbook you have an option to "Add to Existing Contact"

Iphone Recents Item

After clicking on "Add to Existing Contact", a picker shows up and you make a selection. Afterwards it brings you to a ABPersonViewController automatically and allows you to edit or save the new contact:

PersonViewController

I am trying to recreate this but having some issues. In my version, After I create the UnknownPersonViewController and the end user presses "Add to Existing Contact" a picker shows up and allows for selecting from the addressbook similar to native Iphone. But after making a selection the name gets automatically added to the addressbook and no personViewController appears to give the user a choice to add the contact or not. Even if i could just get it to not auto write to the addressbook after making a selection i could just have it show a personviewcontroller in edit mode right away.

So my issue is why is it automatically updating the addressbook after making a selection? Im pushing the ABUnknownpersonviewcontroller onto a UITableviewController navigationcontroller. and im testing on a physical device with iOS 6.01 Here is some code:

 ABRecordRef person = ABPersonCreate ();
 ABMutableMultiValueRef multiValue = ABMultiValueCreateMutable(kABStringPropertyType);
    ABMultiValueAddValueAndLabel(multiValue, call.number,      kABPersonPhoneMainLabel, 
                                 NULL);
    ABRecordSetValue(person, kABPersonPhoneProperty, multiValue, error);
    if(multiValue) CFRelease(multiValue);


 ABUnknownPersonViewController *unknownCtrl = [[ABUnknownPersonViewController alloc] init];
unknownCtrl.displayedPerson = person; //this has a phone number with "main" label
unknownCtrl.allowsActions = YES;
unknownCtrl.allowsAddingToAddressBook = YES;
unknownCtrl.editing=NO;
unknownCtrl.unknownPersonViewDelegate = self;

    // unknownCtrl.addressBook=ABAddressBookCreate(); // I tried setting addressbook to nil and object
unknownCtrl.addressBook=nil;

[self setTitle:call.type forUIViewController:unknownCtrl];

[self.navigationController pushViewController:unknownCtrl animated:YES];

note: i have a similar problem to this post : http://forums.macrumors.com/archive/index.php/t-1023140.html

and perhaps https://discussions.apple.com/thread/1682620?start=0&tstart=0

UPDATE: it seems if i put the kABPersonPhoneMainLabel from the person, then it does not write the phone number to the contact. Aftewards what i did was in didResolveToPerson delegate i call the personviewcontroller in edit mode. This simulates the native behavior. This may answer my own question, thanks everyone.

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • wt u want ?? and wt is ur problem ??? tell me in sort ..thanks :) – iPatel Feb 08 '13 at 15:21
  • hi, my problem is that in my code above, when user presses "add to existing contact" Iphone automatically adds the contact to the person selected and does not allow the user to cancel or edit the contact before merging. In a nutshell , i dont want Iphone to automatically merge the contact, Iphone native does not behave like this. I want Iphone to bring up a ABPersonViewController and leave the user with a choice to cancel to save the merged contact. – j2emanue Feb 08 '13 at 15:24

1 Answers1

0

ABUnknownPersonViewController doesn't expose many customization options, you need to implement your own version. It's not too hard though - the "Create New Contact" button just launches an ABNewPersonViewController, and the "Add to Existing Contact" launches an ABPeoplePickerNavigationController. Your ViewController should act as the delegates for those objects and controls what happens when they are completed.

zeroimpl
  • 2,746
  • 22
  • 19