I try to save a copy of all the entries in the address book, save it to a file as vcards, and then extract this file (or version of this file) and add them back to the address book when I need them in the backup context. I know this question has been asked before, but for the life of me (and my new programming skills) I cannot get it to work:
- (void)grabContacts { ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef contacts = ABAddressBookCopyArrayOfAllPeople(addressBook); NSData *vcards = (NSData *)ABPersonCreateVCardRepresentationWithPeople(contacts); [vcards autorelease]; NSError *error; NSFileManager *fileMgr = [NSFileManager defaultManager]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *folderPath = [paths objectAtIndex:0]; NSString *filePath = [folderPath stringByAppendingPathComponent:@"contacts.dat"]; [NSKeyedArchiver archiveRootObject:vcards toFile:filePath]; NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath: folderPath error:&error]); CFRelease(addressBook); }
I used the solution hosted in Copying contacts from one source to another for the receiving side, but it does not work and due to fuzzy documentation on the Apple side, I destroyed my brain to no avail.
Thanks in advance.
S.
source share