2016-09-21 76 views
0

此應用程序已崩潰,因爲它嘗試訪問隱私敏感的數據而沒有使用說明。該應用程序的Info.plist必須包含一個帶有字符串值的NSContactsUsageDescription項,向用戶解釋應用程序如何使用此數據。如何授權訪問ios 10.0中的手機地址簿?

我加入的.plist NSContactsUsageDescription

不工作 - 設備版本:10.0

KTSContactsManager *addressBookManager = [KTSContactsManager sharedManager]; 
addressBookManager.delegate = self; 
addressBookManager.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES]]; 

if ([isAddressBookTaken isEqualToString:@"false"]) { 
    [addressBookManager importContacts:^(NSArray *contacts) { 
     [EBLogger logWithTag:@"TBLContactManager" withBody:@"importContacts"]; 

     DLPhoneBook *phoneBook = [DLPhoneBook new]; 
     NSMutableArray *mutableArray = [NSMutableArray new]; 

     for (int i = 0; i < contacts.count; ++i) { 
      NSDictionary *record = [contacts objectAtIndex:i]; 
      NSError *err = nil; 
      DLContactRecord *contactRecord = [[DLContactRecord alloc] initWithDictionary:record error:&err]; 

      NSLog(@" %@ %@ %@ '",contactRecord.firstName, contactRecord.lastName, contactRecord.id); 
     } 
    } 

回答

0

你必須在你的plist中添加信息列表,

information plist

這裏是信息n plist爲各種隱私。

添加你想要的plist中的隱私,然後再次檢查。

,並在文件中添加此代碼,

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    contactList=[[NSMutableArray alloc] init]; 
    ABAddressBookRef m_addressbook = ABAddressBookCreate(); 

    if (!m_addressbook) { 
     NSLog(@"opening address book"); 
    } 

    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook); 
    CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook); 

    for (int i=0;i &lt; nPeople;i++) { 
     NSMutableDictionary *dOfPerson=[NSMutableDictionary dictionary]; 

     ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i); 

     //For username and surname 
     ABMultiValueRef phones =(NSString*)ABRecordCopyValue(ref, kABPersonPhoneProperty); 
     CFStringRef firstName, lastName; 
     firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty); 
     lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty); 
     [dOfPerson setObject:[NSString stringWithFormat:@"%@ %@", firstName, lastName] forKey:@"name"]; 

     //For Email ids 
     ABMutableMultiValueRef eMail = ABRecordCopyValue(ref, kABPersonEmailProperty); 
     if(ABMultiValueGetCount(eMail) &gt; 0) { 
      [dOfPerson setObject:(NSString *)ABMultiValueCopyValueAtIndex(eMail, 0) forKey:@"email"]; 

     } 

     //For Phone number 
     NSString* mobileLabel; 
     for(CFIndex i = 0; i &lt; ABMultiValueGetCount(phones); i++) { 
      mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i); 
      if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) 
      { 
       [dOfPerson setObject:(NSString*)ABMultiValueCopyValueAtIndex(phones, i) forKey:@"Phone"]; 
      } 
      else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel]) 
      { 
       [dOfPerson setObject:(NSString*)ABMultiValueCopyValueAtIndex(phones, i) forKey:@"Phone"]; 
       break ; 
      } 

     [contactList addObject:dOfPerson]; 
     CFRelease(ref); 
     CFRelease(firstName); 
     CFRelease(lastName); 
    } 
    NSLog(@"array is %@",contactList); 
    } 
} 

欲瞭解更多關於它的光臨,

http://sugartin.info/2011/09/07/get-information-from-iphone-address-book-in-contacts/

希望它會幫助你。

+0

嗨@KAR感謝您的回答,我做了你已經解釋過的事情,但我一直得到同樣的錯誤。我也刪除應用程序和drived數據文件。 – user3172307

+0

檢查此鏈接是否對您有用,https://forums.developer.apple.com/thread/62229 – KAR

+0

+設置> MyApp>「聯繫人」不會出現! – user3172307