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; }
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.
ios objective-c ios8 abaddressbook
user3191334
source share