0

以下を使用して名前アドレスなどを連絡先に保存するとエラーが発生します

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);

今、アイデアがなくなった

4

1 に答える 1

1

ARCでこの問題が発生している他の人のために、これを修正しました

交換:

ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL);

と:

ABMultiValueAddValueAndLabel(address,(__bridge_retained CFDataRef) addressDict,  kABWorkLabel, NULL);
于 2012-07-17T21:33:04.163 に答える