Catch 22 according to the documentation for using the address book with iOS 6

According to the documentation with iOS6, the address book should be created using ABAddressBookCreateWithOptions.

He also says that if the caller does not have access to db, then this method returns null.

However, access is requested by calling ABAddressBookRequestAccessWithCompletion, which takes the parameter ABAddressBookRef as the parameter.

Thus, according to the documentation, you cannot get ABAddressBookRef in the first place if you do not have access, but in order to access you need to pass ABAddressBookRef as a parameter.

E. Catch 22? How do you then create an ABAddressBookRef?

You have example code / tutorial code for this, but not found.

TIA

+2
source share
2 answers

I am using code like this:

if (ABAddressBookCreateWithOptions) { _book = ABAddressBookCreateWithOptions(NULL, NULL); if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { ABAddressBookRequestAccessWithCompletion(_book, ^(bool granted, CFErrorRef error) { dispatch_async(dispatch_get_main_queue(), ^{ if (granted && !error) { ABAddressBookRevert(_book); } }); }); } } else { _book = ABAddressBookCreate(); } 

where _book is my ABAddressBookRef.

If my application is denied access, then _book will be NULL and you will not be able to access the address book.

+4
source

See my answer here:

fooobar.com/questions/933519 / ...

ABAddressBookRequestAccessWithCompletion is useless and should be ignored.

  • If you need to know the authorization status, call ABAddressBookGetAuthorizationStatus .

  • If authorization is not defined (the user has never run this application), just try to access the database. This will result in an authorization warning.

  • If the user has allowed or denied access, ABAddressBookRequestAccessWithCompletion does nothing, so there is no point calling it.

0
source

All Articles