Advertisement
nsocean

HALAddressBook.m

Jul 9th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "HALAddressBook.h"
  2.  
  3. @implementation HALAddressBook
  4.  
  5. - (BOOL)isAccessGranted
  6. {
  7.  
  8.     ABAddressBookRef m_addressbook =  ABAddressBookCreateWithOptions(NULL, NULL);
  9.  
  10.     __block BOOL accessGranted = NO;
  11.     if (ABAddressBookRequestAccessWithCompletion != NULL) {
  12.         dispatch_semaphore_t sema = dispatch_semaphore_create(0);
  13.         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  14.             @autoreleasepool {
  15.                 // Write your code here...
  16.                 // Fetch data from SQLite DB
  17.             }
  18.         });
  19.        
  20.        
  21.         ABAddressBookRequestAccessWithCompletion(m_addressbook, ^(bool granted, CFErrorRef error)
  22.         {
  23.           accessGranted = granted;
  24.                                                      
  25.           dispatch_semaphore_signal(sema);
  26.                         });
  27.        
  28.         dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
  29.     }
  30.    
  31.     if (accessGranted) {
  32.         // Access has been granted
  33.        self.contacts = (__bridge NSArray *)(ABAddressBookCopyArrayOfAllPeople(m_addressbook));
  34.  
  35.         return YES;
  36.        
  37.     } else {
  38.     // Access has not been granted
  39.     return NO;
  40.     }
  41. }
  42. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement