0

I want to retrieve contacts from AddressBook into my App. The code is having problem for first install, next time onwards it is working fine. For the first installation of App, if AddressBook code executes, the App hangs. After execution of dispatch_semaphore_wait line, the App hangs. I restarted the device, this time App works fine. It is happening if it is first install on new device. How can i fix this?

    CFErrorRef * error = NULL;
    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
__block BOOL isaccess = NO;

    if(ABAddressBookRequestAccessWithCompletion != NULL) {

        dispatch_semaphore_t sema = dispatch_semaphore_create(0);

        //ask to grand or deny access
        ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
            isaccess = granted;
            dispatch_semaphore_signal(sema);
        });

        dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
        dispatch_release(sema);
    }
Sudheer Kumar Palchuri
  • 2,919
  • 1
  • 28
  • 38
  • Calling `wait` with `DISPATCH_TIME_FOREVER` seems like a recipe for hanging an application. What are you trying to accomplish with the semaphore? – Aaron Mar 18 '14 at 17:17
  • You are overcomplicating this. Why do you need to do it this way? – erdekhayser Mar 18 '14 at 23:39

0 Answers0