iOS 8 agregar contacto a la libreta de direcciones

Estoy intentando agregar un contacto a la libreta de direcciones en iOS8. Incapaz de hacerlo más. Aquí está mi código a continuación:

-(void)addPersonToAddressBook { NSString * fullName = integrationDictionary[@"fullName"]; ABPeoplePickerNavigationController *pp =[ABPeoplePickerNavigationController new]; ABAddressBookRef addressBook = [pp addressBook]; ABRecordRef entry = ABPersonCreate(); CFErrorRef cfError=nil; ABRecordSetValue(entry, kABPersonFirstNameProperty, (__bridge CFTypeRef)(fullName) , nil); ABAddressBookAddRecord(addressBook, entry, &cfError); if (ABAddressBookSave(addressBook, &cfError)) { NSString *saveMessage = [NSString stringWithFormat:@"%@ has been added to your address book.", fullName]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Contact Added" message:saveMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } else { NSString *saveMessage = [NSString stringWithFormat:@"There was an error adding %@ to your address book.", fullName]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Uh Oh" message:saveMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } NSLog(@"error is %@", cfError); 

El error aparece como nulo. ¿Alguien ha visto esto antes? ¿Alguna solución?

El error devuelve NULL porque no hay ningún error registrado.

El problema es que [pp addressBook] está devolviendo nil . Por lo tanto, su reference de ABAddressBookRef addressBook es nil .

La solución consiste en utilizar ABAddressBookCreateWithOptions lugar del método [pp addressBook] del ABPeoplePickerNavigationController .

Aquí hay una muestra que funciona bien tanto en iOS 7.1 como iOS 8.1:

 -(void)requestAuthorizationAndAddPersonToAddressBook { // Request authorization to Address Book ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL); if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) { ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) { // First time access has been granted, add the contact [self addPersonToAddressBook]; }); } else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) { // The user has previously given access, add the contact [self addPersonToAddressBook]; } else { // The user has previously denied access // Send an alert telling user to change privacy setting in settings app } } -(void)addPersonToAddressBook { NSString * fullName = @"James Bond"; CFErrorRef abCreateError = nil; ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &abCreateError); if (abCreateError) { NSLog(@"Error occurnetworking: %@", abCreateError); } ABRecordRef entry = ABPersonCreate(); CFErrorRef cfError=nil; ABRecordSetValue(entry, kABPersonFirstNameProperty, (__bridge CFTypeRef)(fullName) , nil); ABAddressBookAddRecord(addressBook, entry, &cfError); if (ABAddressBookSave(addressBook, &cfError)) { NSString *saveMessage = [NSString stringWithFormat:@"%@ has been added to your address book.", fullName]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Contact Added" message:saveMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } else { NSString *saveMessage = [NSString stringWithFormat:@"There was an error adding %@ to your address book.", fullName]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Uh Oh" message:saveMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } if (cfError) { NSLog(@"error is %@", cfError); } }