如何在ios 7中授予访问电话通讯簿的权限?

如何在ios 7中授予访问电话通讯簿的权限?,ios,objective-c,ios7,abaddressbook,Ios,Objective C,Ios7,Abaddressbook,上述代码在模拟器中运行良好,但当我在iPhone5c中运行应用程序时,它并没有请求我的许可,而且我无法从设备地址簿中获取电话号码 帮我解决这个问题。 提前谢谢。在您的viewDidLoad方法中调用此行 NSMutableArray *arrContacts=[[NSMutableArray alloc]init]; CFErrorRef *error = nil; ABAddressBookRef addressbook = ABAddressBookCreateWith

上述代码在模拟器中运行良好,但当我在iPhone5c中运行应用程序时,它并没有请求我的许可,而且我无法从设备地址簿中获取电话号码

帮我解决这个问题。
提前谢谢。

在您的
viewDidLoad
方法中调用此行

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)
    {

    }

viewDidLoad
方法中调用此行

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)
    {

    }

viewDidLoad
方法中调用此行

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)
    {

    }

viewDidLoad
方法中调用此行

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)
    {

    }

尝试从手机中删除应用程序,然后重新安装。尝试从手机中删除应用程序,然后重新安装。尝试从手机中删除应用程序,然后重新安装。尝试从手机中删除应用程序,然后重新安装。从设备中删除应用程序并重新安装后,它工作正常。哦,k,k,好朋友,我使用了上述方法,每次安装应用程序都可以正常工作,从设备中删除应用程序并重新安装后也可以正常工作。哦,好朋友,我使用了上述方法,每次安装应用程序都可以正常工作,从设备中删除应用程序并重新安装后也可以正常工作。哦,k k fine friend,我第一次使用上述方法安装应用程序时效果良好从设备中删除应用程序并重新安装后效果良好。噢,k k fine friend,我第一次使用上述方法安装应用程序时效果良好