Since updating to iOS 6 I've noticed that my code to add a contact to iPhone's address book no longer works. I believe this is a permission related problem, since Apple now requires user permission before accessing contacts (fixing this issue).
I expected the app to automatically ask permission to access contacts, like in the screenshot below, but it doesn't. Trying to add the contact just fails with ABAddressBookErrorDomain error 1
.
Do I need to programmatically launch the access to contacts request dialog? How is that done?
That did the perfect trick for me!
On iOS6, apple introduce new privacy control, user can control the accessment of contact and calender by each app. So, in the code side, you need to add some way to request the permission. In iOS5 or before, we can always call
to get the addressbook without any problem, but in iOS6, if you don't have permission, this call will just return empty pointer. That why we need to change the method to get ABAddressBookRef.
In the code,semaphore is used for blocking until response, while ABAddressBookRequestAccessWithCompletion will ask for permission if the app didn't ask before. Otherwise it will just follow the settings in Settings-Privacy-Contact.
SOURCE: http://programmerjoe.blogspot.com/2012/10/ios6-permissions-contacts.html
As per this documentation on apple's site (scroll down to Privacy in the middle of the page), access to the address book must be granted before it can be access programmatically. Here is what I ended up doing.
Update For iOS 9 and later:
From Apple website :
This code shows how to set the permission and how to get all the contacts from the phone and show the contacts in the list with the label tag
To get Addressbook in ios
If anyone have problem with addressBook in iOS5 then Use
Insted of