iDev: iOS6 AddressBook Contacts Access Code

In iOS 6 :  Access the Address Book details by this code:

-(BOOL)isABAddressBookCreateWithOptionsAvailable {
return &ABAddressBookCreateWithOptions != NULL;
}

your method code :{

CFErrorRef error = NULL;

ABAddressBookRef addressBook;
//ABAddressBookRef addressBook = ABAddressBookCreate();
if ([self isABAddressBookCreateWithOptionsAvailable]) {
addressBook = ABAddressBookCreateWithOptions(NULL,&error);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
// callback can occur in background, address book must be accessed on thread it was created on
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
NSLog(@”error == %@”,error);
} else if (!granted) {
NSLog(@”error == Not granted “);
} else {
// access granted
bool wantToSaveChanges = YES;

bool didSave;

CFErrorRef error = NULL;
if (ABAddressBookHasUnsavedChanges(addressBook)) {

if (wantToSaveChanges) {

didSave = ABAddressBookSave(addressBook, &error);

if (!didSave) {/* Handle error here. */ NSLog(@”Not change”);}

} else {

ABAddressBookRevert(addressBook);

}

}

}
});
});

}
else {

}

Keep Coding 🙂

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s