我正在使用以下代码,我的应用程序在iOS 7及以上版本上不要求iOS 6的许可,它要求联系人权限访问。在iOS 6上,它也不会在隐私设置中显示应用程序。我已阅读其他一些帖子但未找到任何解决方案。
App crashed in iOS 6 when user changes Contacts access permissions
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
__block CDNDeviceContact *controller = self;
// Request authorization to Address Book
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef,
^(bool granted, CFErrorRef error) {
if (granted)
[controller loadContacts];
else [controller doAlertForContact];
});
} else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
// The user has previously given access, add the contact
[self loadContacts];
} else {
[controller doAlertForContact];
}
if (addressBookRef) CFRelease(addressBookRef);
}
答案 0 :(得分:2)
如果之前已向用户显示获得许可的请求,则不会再次显示该请求。根据{{3}},
首次请求访问时,系统仅向用户请求权限。以后的呼叫使用用户授予的权限。
如果在模拟器中测试,我建议你去iOS模拟器 - >重置内容和设置,以便您能够模拟事件。
答案 1 :(得分:0)
您不需要SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO
,也无需创建ABAddressBookRef
。
对我而言,这就像魅力一样:
if (ABAddressBookGetAuthorizationStatus) {
switch (ABAddressBookGetAuthorizationStatus()) {
case kABAuthorizationStatusNotDetermined:{
ABAddressBookRequestAccessWithCompletion(self.addressBook, ^(bool granted, CFErrorRef error) {
self.addContactButton.enabled = granted;
if (granted) {
// granted
} else {
// User denied access
}});
} break;
case kABAuthorizationStatusDenied: break;
case kABAuthorizationStatusAuthorized: break;
default: break;
}
}