简体   繁体   中英

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;
           });

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM