NSMutableArray *arrContacts=[[NSMutableArray alloc]init];
CFErrorRef *error = nil;
ABAddressBookRef addressbook = ABAddressBookCreateWithOptions(NULL, error);
__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we are used on the iOS 6
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@autoreleasepool {
// Write your code here...
// Fetch data from SQLite DB
}
});
ABAddressBookRequestAccessWithCompletion(addressbook, ^(bool granted, CFErrorRef error) {
accessGranted = granted;
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}
else { // we're on iOS 5 or older
accessGranted = YES;
}
if (accessGranted)
{
}
Вышеупомянутый код отлично работает в симуляторе, но когда я запускаю приложение на Iphone 5c, он не спрашивает у меня разрешения, и я не могу получить номера телефонов из адресной книги устройства.
помогите мне решить эту проблему. Заранее спасибо.