使用 Toggle 启用-禁用 IOS 联系人访问
Make Enable-Disable IOS Contacts Access using Toggle
我需要在用户关闭(禁用)时使用切换关闭来自 myApp 的联系人访问。
以及在切换将打开(启用)时获得联系人权限。
知道如何修复。
首先我想让你知道 Apple 不允许以任何 Apple 授权的方式以编程方式修改隐私设置......所以如果你想处理这个问题你可以检查权限,如果它被授予......然后你可以处理你的事件a/c......这个方法将触发来自本地OS的警报,要求访问...... ..
//Ask user to grant the permission to access contacts
- (void)requestPermissionForContactsAccessAndFetchWithCompletion
{
ABAuthorizationStatus status = ABAddressBookGetAuthorizationStatus();
if (status != kABAuthorizationStatusAuthorized && status != kABAuthorizationStatusNotDetermined) {
// tell user to enable contacts in privacy settings
NSLog(@"You previously denied access: You must enable access to contacts in settings");
}
CFErrorRef error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
if (error)
{
if (addressBook) CFRelease(addressBook);
}
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (error) {
NSLog(@"ABAddressBookRequestAccessWithCompletion error: %@", CFBridgingRelease(error));
}
if (granted) {
//Get all contact if access is granted--This will call when access granted
[self getContactsFromAddressBook:addressBook];
}else{
}
});
}
如果您需要更多帮助,请告诉我....
我需要在用户关闭(禁用)时使用切换关闭来自 myApp 的联系人访问。 以及在切换将打开(启用)时获得联系人权限。
知道如何修复。
首先我想让你知道 Apple 不允许以任何 Apple 授权的方式以编程方式修改隐私设置......所以如果你想处理这个问题你可以检查权限,如果它被授予......然后你可以处理你的事件a/c......这个方法将触发来自本地OS的警报,要求访问...... ..
//Ask user to grant the permission to access contacts
- (void)requestPermissionForContactsAccessAndFetchWithCompletion
{
ABAuthorizationStatus status = ABAddressBookGetAuthorizationStatus();
if (status != kABAuthorizationStatusAuthorized && status != kABAuthorizationStatusNotDetermined) {
// tell user to enable contacts in privacy settings
NSLog(@"You previously denied access: You must enable access to contacts in settings");
}
CFErrorRef error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
if (error)
{
if (addressBook) CFRelease(addressBook);
}
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (error) {
NSLog(@"ABAddressBookRequestAccessWithCompletion error: %@", CFBridgingRelease(error));
}
if (granted) {
//Get all contact if access is granted--This will call when access granted
[self getContactsFromAddressBook:addressBook];
}else{
}
});
}
如果您需要更多帮助,请告诉我....