85261

How to give permission to access phone Addressbook in ios 10.0?

Question:

<blockquote>

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSContactsUsageDescription key with a string value explaining to the user how the app uses this data.

</blockquote>

I added to the .plist NSContactsUsageDescription

<strong>doesn't work - device version:10.0</strong>

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); } }

Answer1:

You have to add information list in your plist,

<a href="https://i.stack.imgur.com/5wxux.png" rel="nofollow"><img alt="information plist" class="b-lazy" data-src="https://i.stack.imgur.com/5wxux.png" data-original="https://i.stack.imgur.com/5wxux.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Here is information plist for various privacy.

Add Privacy that you want in you plist and check again.

and ADD this code in your file,

- (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); } }

For more about it visit,

<a href="http://sugartin.info/2011/09/07/get-information-from-iphone-address-book-in-contacts/" rel="nofollow">http://sugartin.info/2011/09/07/get-information-from-iphone-address-book-in-contacts/</a>

Hope it will help you.

Recommend

  • View wont update image(iphone app)
  • How to add object at first index of NSArray
  • Doctrine DBAL: Updating timestamp field with 'NOW()' value
  • Getting NULL by ABAddressBookGetPersonWithRecordID
  • How to get Contact's Nickname Windows Phone 8.1
  • Is there a way to return a sorted key list from a hash?
  • How to swipe multi buttons with one touch
  • Check if an array of custom objects contains an object with a certain date
  • Weird UIView coordinate issue
  • Unable to extract string using NSRegularExpression (regex pattern) - iphone
  • Encoding issue with ASIHttpRequest
  • didUpdatePushCredentials not get called
  • Using Sax parsing to edit and write XML in VB6
  • Build Successful but not running on simulator
  • how to save the state in userdefaults of accessory checkmark-iphone
  • How to change the font size of a single index for UISegmentedControl?
  • Django: Count of Group Elements
  • How to add date and time under each post in guestbook in google app engine
  • Sending data from AppleScript to FileMaker records
  • SSO with signing and signature validation doesn't work
  • MySQL WHERE-condition in procedure ignored
  • How to show dropdown in excel using jrxml (jasper api)?
  • Importing jscolor library in angular 2
  • Release, debug version and Authorization Google?
  • Websockets service method fails during R startup
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • How to get next/previous record number?
  • Apache 2.4 - remove | delete | uninstall
  • Proper way to use connect-multiparty with express.js?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Trying to get generic when generic is not available
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • embed rChart in Markdown
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Sorting a 2D array using the second column C++
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal