ios - Why i can't get contents of adressbook -
i trying content of adressbook these codes.
abaddressbookref addressbook = abaddressbookcreate(); if (addressbook != nil) { nslog(@"succesful."); nsarray *allcontacts = (__bridge_transfer nsarray *)abaddressbookcopyarrayofallpeople(addressbook); nsuinteger = 0; nslog(@"countt=%lu",(unsigned long)[allcontacts count]); }
i succesful log count "0", use simulator , added contacts in test. ios 7 , xcode 5.
i glad take advice or help.
the problem test nil meaningless. if have not been granted access user address book, result of abaddressbookcreate()
still non-nil. useless!
so, moral is: test see whether have been granted access (abaddressbookgetauthorizationstatus
) and, if access has been neither granted nor denied, request formally (abaddressbookrequestaccesswithcompletion
).
Comments
Post a Comment