Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the problem is this: you are using a semaphore to block the thread until "the green light" appears. But you are executing this code on the thread 0 (the main thread, that manages the user interface). For this reason you are blocking all changes in the user interface, including the alert requesting access to contacts.</p> <p>EDIT for the new code First thing: try on a device. For some reason, Simulator always return authorized even if not: <a href="https://stackoverflow.com/questions/12602984/abaddressbookgetauthorizationstatus-in-simulator-always-returns-kabauthorization">ABAddressBookGetAuthorizationStatus in simulator always returns kABAuthorizationStatusAuthorized</a> . </p> <p>Second thing, your "if (accessGranted)" won't be executed the first time the user authorize the app, because it is executed <em>before</em> the completion block (the completion block waits the user decision), but the code immediately after the block is executed immediately. You should move that code in another function (called after the completion block only once authorized, for example). But, for testing purpose, this code should work the second time you try to access the AB, once authorized.</p> <p>Your accessGranted code is fine except one thing: if you have an array of 250 records, you are trying to access the record 250 (that doesn't exists, the last record is number 249). Change this line</p> <pre><code>ABRecordRef ref = CFArrayGetValueAtIndex(all,recordsCount); </code></pre> <p>with this</p> <pre><code>ABRecordRef ref = CFArrayGetValueAtIndex(all,recordsCount-1); </code></pre> <p>I tried and it works</p>
 

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