Question

I am developing an application to backup the whole address book into amazon s3,but i cant able to find any direct iphone api to get the whole address book into any data structure.

I tried the following code,to write the address book array to a file in document directory

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *addressPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"AddressBook.plist"];


ABAddressBookRef addressBook = ABAddressBookCreate();

NSMutableArray *allPeople = [[[(NSArray*) ABAddressBookCopyArrayOfAllPeople(addressBook)autorelease]mutableCopy]autorelease];

[allPeople writeToFile:addressPath atomically:YES];

But the problem is file is not getting created in document directory....

Any suggestions appreciated....

Thanks in advance...

Was it helpful?

Solution

Im not 100% sure, but Accessing the entire addressbook at once probably is not allowed. Apple has the AddressBookPeoplePicker for a reason, though picking everyone in the AddressBook one person at a time would be a pain.

You may be able to set up a loop to run through the address book programatically. Then add it to your own NSMutableArray.

OTHER TIPS

You would require this function: http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html#//apple_ref/doc/uid/TP40007210

An Array of all the people is returned. Read the documentation for more. Best of Luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top