我使用以下代码自动授权访问iOS联系人。
这在iOS7中运行正常,但在iOS6中,它无法提示用户授权访问联系人。我无法理解为什么iOS6会自动授权访问。
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
// First time access has been granted, add the contact
if(granted)
[self accessTheContact]; });
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
// The user has previously given access, add the contact
[self accessTheContact];
}
else {
[self showAlert];
}
在ios 6中,如果阻止所有时间,则进入其他。所以在ios 6中不会显示获取许可的警报视图