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?
Swift 3. Don't forget to import Contacts
Had some problems with yunas code on iOS6.1 in Xcode5. With some small adaptions it worked for me.
The problem was that ARC in iOS 6, did not allows
dispatch_release(sema);
Here's the working code. Note: I usem_addressbook
instead ofaddressbook
as ABAddressBookRef!ViewController.m
For add description to alert use in InfoPlist.strings.
NSContactsUsageDescription = "TESTING!";
For contacts framework:
With iOS 6 you have to ask permission like this