Address Book Authorization in iOS8

I'm having a problem getting permission to access AddressBook, since I updated iOS 8.

In iOS 7, the system asks the user if my application is allowed to access his address book, but with iOS8 there were no requests. Each time I check the ABAddressBookGetAuthorizationStatus object before I start my "MyGetAddressesOfContacts" function, the status will be equal to kABAuthorizationStatusNotDetermined. As you can see here:

if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusDenied) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No permission" message:@"This App has no permition to access your contacts. Please check it in your privacy settings of your device." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; return nil; } // This AlertView pops up every time! if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Why this App needs your contacts" message:@"In the following your device will ask you whether this App is allowed to access your contacts. [...]" delegate:self cancelButtonTitle:@"I understand" otherButtonTitles: nil]; [alert show]; } 

After this check, I'm going to run the function MyGetAddressesOfContacts, which looks like this:

 ABAddressBookRef addressBook = ABAddressBookCreate(); NSArray *contactArr = (NSArray *)CFBridgingRelease(ABAddressBookCopyArrayOfAllPeople(addressBook)); NSMutableDictionary *dPersons = [[NSMutableDictionary alloc] init]; for (int i = 0; i < [contactArr count]; i++) { ABRecordRef person = (ABRecordRef)CFBridgingRetain([contactArr objectAtIndex:i]); NSString *firstName = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty); NSString *lastName = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty); NSString *sPersonName = [NSString stringWithFormat:@"%@ %@", firstName, lastName]; ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty); NSString *sAddress; for(CFIndex j = 0; j < ABMultiValueGetCount(address); j++) { CFDictionaryRef addressDict = ABMultiValueCopyValueAtIndex(address, j); CFStringRef streetValue = CFDictionaryGetValue(addressDict, kABPersonAddressStreetKey); CFStringRef cityValue = CFDictionaryGetValue(addressDict, kABPersonAddressCityKey); CFStringRef countryValue = CFDictionaryGetValue(addressDict, kABPersonAddressCountryKey); sAddress = [NSString stringWithFormat:@"%@ %@, %@", streetValue, cityValue, countryValue]; [dPersons setObject:sAddress forKey: [NSString stringWithFormat:@"%@%d %ld", @"AddressFromNameID", i, j]]; } [dPersons setObject:sPersonName forKey: [NSString stringWithFormat:@"%@ %d", @"NameWithID", i]]; } return dPersons; 

Hope someone can help.

+7
ios objective-c ios8 abaddressbook
source share
1 answer

After you created AB ...

 ABAddressBookRef addressBook = ABAddressBookCreate(); 

call the following ...

 ABAddressBookRequestAccessWithCompletion(addressBook, nil); 

A prompt appears to allow the user to allow your application access to "contacts"; As a second parameter, you can get a callback and behave accordingly. See Apple Documentation

+3
source share

All Articles