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?
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
Post a Comment