2016-01-12 173 views

回答

0

首先,我想讓你知道,蘋果不允許以任何授權的方式修改隱私設置,程序化........所以,如果你想處理這個問題,你可以檢查許可,如果它被授予或沒有.....然後你可以處理你的事件a/c到....這種方法將從本機操作系統發出警報,要求訪問....

//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{ 


     } 

    }); 

} 

讓我知道你是否需要更多幫助....

+1

謝謝@Prasanna ... –