if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
if (granted) {
// First time access has been granted, add the contact
[self prepareContactsIDs];
} else {
UIAlertView *accessDenied = [[UIAlertView alloc] initWithTitle:@"Need Access to Addressbook" message:@"KeepItClean requires an access to addressbook in order to be usable" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[accessDenied show];
}
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
// The user has previously given access, add the contact
if ([self isFirstRun]) {
[self prepareContactsIDs];
}
}
else {
// The user has previously denied access
// Send an alert telling user to change privacy setting in settings app
UIAlertView *accessDenied = [[UIAlertView alloc] initWithTitle:@"Need Access to Addressbook" message:@"KeepItClean requires an access to addressbook in order to be usable" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[accessDenied show];
}
这里有一些我不明白的地方,当提示用户授予访问权限时,如果他点击取消,我没有显示我的第二个 UIAlertView,即 (accessDenied) 警报视图。
我也觉得有些东西我不明白与调度和队列有关。