user741076
user741076

Reputation: 63

App Crashes inside dispatch_queue in iPhone

In one of my apps I am using dispatch_queue and inside this I declared a dispatch_asyc queue for checking the address book. Now when compiler comes to the return statement, it causes app to crash. Below is my source code.

   dispatch_queue_t queue = dispatch_queue_create("abc", NULL);

   dispatch_async(queue, ^{
       // Request authorization to Address Book
       ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
       if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
           ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
               // First time access has been granted...

               // All good.
               completionBlock?completionBlock(YES):nil;

               dispatch_async(queue, ^{
                   if (addressBookRef) {
                       CFRelease(addressBookRef);
                   };
               });

               return;
           });

Upvotes: 1

Views: 121

Answers (1)

Skotch
Skotch

Reputation: 3091

According to the documentation on Address Book, you cannot use ABAddressBookRef across threads

Important: Instances of ABAddressBookRef cannot be used by multiple threads. Each thread must make its own instance by calling ABAddressBookCreate.

See this question for some more ideas on how to do this:

Upvotes: 2

Related Questions