允许应用程序使用联系人弹出不显示ios7

时间:2014-01-06 11:36:43

标签: iphone ios7 abaddressbook

我正在使用我想要获取联系人的应用程序。问题是该应用程序仅首次要求应用程序使用联系人。即使我删除了应用程序,清理它并再次运行,应用程序是不是在下次运行时要求弹出。我调试了代码并发现我第一次给出的权限是执行的。如何解决这个问题。下面是我在视图中写的代码加载了。

 CFErrorRef *error=nil;
ABAddressBookRef addressbook=ABAddressBookCreateWithOptions(NULL, error);
CFArrayRef allpeople=ABAddressBookCopyArrayOfAllPeople(addressbook);
CFIndex npeople=ABAddressBookGetPersonCount( addressbook );


ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
        if (granted) {

            for ( int i = 0; i < npeople; i++ )
            {
                ABRecordRef ref = CFArrayGetValueAtIndex( allpeople, i );
                NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(ref, kABPersonFirstNameProperty));
                NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(ref, kABPersonLastNameProperty));
                NSLog(@"Name:%@ %@", firstName, lastName);    }


            // First time access has been granted, add the contact
        } else {
            // User denied access
            // Display an alert telling user the contact could not be added
        }
    });
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {


    for ( int i = 0; i < npeople; i++ )
    {
        ABRecordRef ref = CFArrayGetValueAtIndex( allpeople, i );
        NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(ref, kABPersonFirstNameProperty));
        NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(ref, kABPersonLastNameProperty));
        NSLog(@"Name:%@ %@", firstName, lastName);    }


    // The user has previously given access, add the contact
}
else {


    for ( int i = 0; i < npeople; i++ )
    {
        ABRecordRef ref = CFArrayGetValueAtIndex( allpeople, i );
        NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(ref, kABPersonFirstNameProperty));
        NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(ref, kABPersonLastNameProperty));
        NSLog(@"Name:%@ %@", firstName, lastName);    }


    // The user has previously denied access
    // Send an alert telling user to change privacy setting in settings app
}

1 个答案:

答案 0 :(得分:2)

请按照以下步骤

转到设备的Setting->General->Reset->Reset Location & Privacy.

然后它应该请求你的许可。