iphone - Programmatically Request Access to Contacts -


since updating ios 6 i've noticed code add contact iphone's address book no longer works. believe permission related problem, since apple requires user permission before accessing contacts (fixing this issue).

i expected app automatically ask permission access contacts, in screenshot below, doesn't. trying add contact fails abaddressbookerrordomain error 1.

do need programmatically launch access contacts request dialog? how done?

access contacts

as per this documentation on apple's site (scroll down privacy in middle of page), access address book must granted before can access programmatically. here ended doing.

  #import <addressbookui/addressbookui.h>    // request authorization 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 contact           [self _addcontacttoaddressbook];       } else {           // user denied access           // display alert telling user contact not added       }     });   }   else if (abaddressbookgetauthorizationstatus() == kabauthorizationstatusauthorized) {     // user has given access, add contact     [self _addcontacttoaddressbook];   }   else {     // user has denied access     // send alert telling user change privacy setting in settings app   } 

update ios 9 , later:

from apple website :

important

the address book ui framework deprecated in ios 9. use apis defined in contactsui framework instead. learn more, see contactsui


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -