0

I have an error when using the following to save name address etc to contacts

IBAction:

ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;
[self.navigationController pushViewController:unknownPersonViewController animated:YES];



}
 - (ABRecordRef)buildContactDetails {
NSLog(@"building contact details");
ABRecordRef person = ABPersonCreate(); 
CFErrorRef  error = NULL;  

// firstname
ABRecordSetValue(person, kABPersonFirstNameProperty, @"Don Juan", NULL);

// email
ABMutableMultiValueRef email = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(email, @"myemail.hotmail.com", CFSTR("email"), NULL);
ABRecordSetValue(person, kABPersonEmailProperty, email, &error);
CFRelease(email); 

// Start of Address
ABMutableMultiValueRef address =   ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);  
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init];
[addressDict setObject:@"Hig Street" forKey:(NSString *)kABPersonAddressStreetKey];   
[addressDict setObject:@"WR11" forKey:(NSString *)kABPersonAddressZIPKey];  
[addressDict setObject:@"Evesham" forKey:(NSString *)kABPersonAddressCityKey]; 
ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonAddressProperty, address, &error); 


// End of Address

if (error != NULL) 
    NSLog(@"Error: %@", error);


return person;

Im getting an error in the following line:

ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL);

Specifically addressDict,

"Implicit conversion of the Objective-C pointer ARC error requires a  bridged cast"

So I tried:

ABMultiValueAddValueAndLabel(address, (__bridge_retained CFDataRef)dataRef, kABWorkLabel, NULL);

Now im out of ideas

JSA986
  • 5,870
  • 9
  • 45
  • 91
  • Use `CFMutableDictionary` instead – Dustin Jul 17 '12 at 19:51
  • Its asking for `__bridge to covert directly (no change in ownership)` or `_bridge retaind to make ARC onbject availible as +1 "CFType ref aka consist void)` – JSA986 Jul 17 '12 at 21:23
  • Maybe try this: `ABMultiValueAddValueAndLabel(address, (__bridge_transfer CFDataRef)dataRef, kABWorkLabel, NULL);` ` – pasawaya Jul 17 '12 at 22:44

1 Answers1

1

Ok fixed this, for anyone else that has this issue with ARC

Replace:

ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL);

with:

ABMultiValueAddValueAndLabel(address,(__bridge_retained CFDataRef) addressDict,  kABWorkLabel, NULL);
JSA986
  • 5,870
  • 9
  • 45
  • 91