使用以下内容将姓名地址等保存到联系人
时出错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);
现在我没有想法
答案 0 :(得分:1)
好的,对于有这个ARC问题的其他人
解决了这个问题替换:
ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL);
使用:
ABMultiValueAddValueAndLabel(address,(__bridge_retained CFDataRef) addressDict, kABWorkLabel, NULL);