Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As per <a href="https://developer.apple.com/library/ios/documentation/Contacts/Reference/Contacts_Framework/" rel="noreferrer">this documentation</a> on apple's site (scroll down to Privacy in the middle of the page), access to the address book <strong>must be granted</strong> before it can be access programmatically. Here is what I ended up doing.</p> <pre><code> #import &lt;AddressBookUI/AddressBookUI.h&gt; // Request authorization to Address Book ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL); if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) { if (granted) { // First time access has been granted, add the contact [self _addContactToAddressBook]; } else { // User denied access // Display an alert telling user the contact could not be added } }); } else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) { // The user has previously given access, add the contact [self _addContactToAddressBook]; } else { // The user has previously denied access // Send an alert telling user to change privacy setting in settings app } </code></pre> <p><strong>Update For iOS 9 and later:</strong></p> <p>From Apple website :</p> <blockquote> <p>Important</p> <p>The Address Book UI framework is deprecated in iOS 9. Use the APIs defined in the ContactsUI framework instead. To learn more, see <a href="https://developer.apple.com/reference/contactsui" rel="noreferrer">ContactsUI</a></p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload