Iphone ABUnknownPersonViewController using allowAddingToAddressBook = YES

Let me explain what I want to do first. In the original Iphone on the โ€œRecentsโ€ tab, if you click on a contact that is not found in any address book, you have the option โ€œAdd to existing contactโ€

Iphone Recents Item

After clicking the "Add to existing contact" button, the collector will appear, and you will make a choice. Subsequently, it automatically brings you ABPersonViewController and allows you to edit or save a new contact:

PersonViewController

I am trying to recreate this, but have some problems. In my version, after I create UnknownPersonViewController and the end user clicks "Add to existing contact", a collector appears and allows you to select from the address book, similar to the built-in Iphone. But after you make a choice, the name is automatically added to the address book, and not a single personViewController gives the user the ability to add a contact or not. Even if I could just make it not automatically write to the address book after the selection, I could just show that it immediately displays the personview manager in edit mode.

So my problem is why does it automatically update the address book after selection? Im clicking ABUnknownpersonviewcontroller on a UITableviewController navigationcontroller. and im testing on a physical device with iOS 6.01 Here is the 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 with this post: http://forums.macrumors.com/archive/index.php/t-1023140.html

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

UPDATE: it seems that if I put kABPersonPhoneMainLabel from a person, then he will not write the phone number to the contact. Be that as it may, in the didResolveToPerson delegate, I call manviewcontroller in edit mode. This mimics natural behavior. This may answer my question, thanks everyone.

+4
source share
1 answer

ABUnknownPersonViewController does not provide many settings, you need to implement your own version. This is not too complicated - the "Create a new contact" button launches only ABNewPersonViewController , and the "Add to existing contact" launches ABPeoplePickerNavigationController . Your ViewController should act as a delegate for these objects and control what happens when they are completed.

0
source

All Articles