Using VCards with ABAddressBook in iOS 5.0 / Xcode 4.2

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.

+4
source share
1 answer

Nevermind I found my problem. I did not unzip the files when I restored them. Stupid me gets what stupid me deserves to program without copious amounts of alcohol.

0
source

Source: https://habr.com/ru/post/1387344/


All Articles