0

I am working on a contact management application that syncs contact data from Microsoft Exchange.

I would like to be able to create contacts in the iOS address book that are local contacts only - i.e they will exist only on the device and will not be synced to Microsoft Exchange.

I was under the assumption that I could create a contact using ABPersonCreateInSource however as it turns out that function requires a particular source to create the contact in. However it's not possible to create a source (i.e. you can't just create the "local" source). You need to enumerate the existing sources that are on the device.

What I am finding is that if you are syncing the device with exchange then you will have one or more kABSourceTypeExchange sources, but no local sources. However if you don't have an exchange source then you'll have kABSourceTypeLocal as your source.

Is anyone aware of how it is possible to create a contact that is local only, and which won't be synced with Microsoft exchange in the case where there's an exchange account configured on the device?

Lee
  • 3,996
  • 3
  • 33
  • 37

1 Answers1

0

I had this problem recently, I now this is an old post and since there was not a straight answer online I'll leave my 2 cents here for anyone who could have this problem.

You can create a local only contact, I found that creating this contact is not exactly a good idea, on iphone 4 local contacts will not appear on any group but might be found if All contacts are displayed, on iphone 5 and up, these contacts will not appear on any group cannot be found if All contacts are displayed, and if the only way to access to those contacts was through the recents calls log which will show the contact info, or manually searching the contacts since it wont be displayed on quick search

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
ABRecordRef nativebook = ABAddressBookGetSourceWithRecordID(addressBookRef, kABSourceTypeLocal);
ABRecordRef myLocalContact = ABPersonCreateInSource(nativebook);
CFRelease(nativebook);
//... fill the contact and save it to the addressbook.
CFErrorRef error = NULL;
ABAddressBookAddRecord(addressBookRef, myLocalContact, &error);
ABAddressBookSave(addressBookRef, &error);
CFRelease(addressBookRef);

These contacts will not be synced with the exchange account. I heavily recommend to instead of adding them to the local contacts add it to the working iCloud account, this way contact will not show on the exchange account and this contacts can be removed anytime the user wants.

Alfonso Nava
  • 137
  • 6
  • Interesting thanks - when you say add to the local iCloud account what does that entail? – Lee Aug 06 '15 at 19:55
  • In your Settings>Mail,Contacts, Calendars. you could have many iCloud accounts, or Gmail(also recognized as iCloud from within sources), these accounts are recognized by source to be CardDAV but when trying to save on those you need to use the MobileMe type to let the user sync – Alfonso Nava Aug 06 '15 at 20:31