保存到联系人时出

保存到联系人时出

使用以下内容将姓名地址等保存到联系人时出现错误

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;


我在以下行中收到错误:

ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL);


具体是addressDict

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


所以我尝试了:

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


现在我没有想法了

最佳答案

确定,对于其他与ARC有关的问题,请修复此问题

更换:

ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL);


与:

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

关于objective-c - 从应用程序保存到联系人时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11529710/

10-14 23:31