2016-05-31 27 views

回答

0

如果你想顯示給用戶的自定義信息,要求允許使用他們的聯繫人或地址簿,而不是上面顯示一個默認的時候,你需要這個字段添加到您的Info.plist文件:

NSContactsUsageDescription 

這裏是蘋果開發者鏈接相同: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW14

+0

是否有產生的消息訪問地址簿中的任何系統?其實我已經在Plist.But添加「NSContactUsageDescription」我怎麼能在我的應用程序中調用該方法 –

+0

@DivakarReddy不存在任何相同的方法,但是一旦創建用於提取聯繫人的Addressbook對象,它就會請求權限。 –

+0

我已經在Plist.But中添加了「NSContactsUsageDescription」如何調用該方法在我的app.Which類引用我可以用來調用該方法。假設我們使用MapKit.we需要使用「WhenInUseAuthorizationMethod」 –

0
// Check the authorization status of your application for Address Book 
-(void)checkAddressBookAccess 
{ 
    switch (ABAddressBookGetAuthorizationStatus()) 
    { 
      // Update our UI if the user has granted access to their Contacts 
     case kABAuthorizationStatusAuthorized: 
      [self showAddressBook]; 
      break; 
      // Prompt the user for access to Contacts if there is no definitive answer 
     case kABAuthorizationStatusNotDetermined : 
      [self requestAddressBookAccess]; 
      break; 
      // Display a message if the user has denied or restricted access to Contacts 
     case kABAuthorizationStatusDenied: 
     case kABAuthorizationStatusRestricted: 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" 
                  message:@"You have not granted access to your contacts or you have revoked it earlier." 
                  delegate:nil 
                cancelButtonTitle:@"OK" 
                otherButtonTitles:nil]; 
      [alert show]; 
     } 
      break; 
     default: 
      break; 
    } 
} 

// Prompt the user for access to their Address Book data 
-(void)requestAddressBookAccess 
{ 
    TF_Message_View_Controller * __weak weakSelf = self; 

    ABAddressBookRequestAccessWithCompletion(self.addressBook, ^(bool granted, CFErrorRef error) 
              { 
               if (granted) 
               { 
                dispatch_async(dispatch_get_main_queue(), ^{ 
                 [weakSelf showAddressBook]; 

                }); 
               } 
              }); 
} 
+0

在我的應用程序中,他們使用了兩個聯繫人以及地址簿。如何顯示聯繫人的用戶訪問權限?您可以編寫訪問權限的代碼。它非常緊急我? –

0

如果你想顯示警報請求許可,您可以使用下面的代碼

該代碼可以使用聯繫人的框架,它僅適用於iOS 9.0或更高版本

- (void)checkContactStoreAccess { 
    self.contactsStrore = [[CNContactStore alloc] init]; 

    switch ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]) { 
     case CNAuthorizationStatusAuthorized: { 
      [self fetchContactsFromContactStore]; 
      break; 
     } 
     case CNAuthorizationStatusNotDetermined:{ 
      [self requestContactsAccess]; 
      break; 
     } 
     case CNAuthorizationStatusDenied: 
     case CNAuthorizationStatusRestricted:{ 
      //show info that access denied for contact and redirect user to settings with 
      [UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; 
     } 
    } 
} 
- (void)requestContactsAccess { 
    typeof(self) __weak weakSelf = self; 
    [self.contactsStrore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) { 
     [weakSelf fetchContactsFromContactStore]; 
    }]; 
} 
+0

在我的應用程序中,他們已經使用了兩個聯繫人以及地址簿。如何顯示聯繫人的用戶訪問權限。您可以編寫訪問權限的代碼。它對我來說非常緊迫嗎? –

+0

我們有任何關於代碼的問題請發送到here.It對我更有用嗎? –

+0

我應該在fetchContactsFromContactStore方法下寫什麼 –

相關問題