Reputation: 1011
In my application, i am trying to save name and contact number to address book.
However, when saving (using the below code), i am getting the error:
/Users/mobility/Desktop/STAXApplication/STAXApplication/AccountsAndContactsViewController.m:739:61: Implicit conversion of Objective-C pointer type 'NSString *' to C pointer type 'CFTypeRef' (aka 'const void *') requires a bridged cast
The code i am using is:
-(void)addRecord:(NSString *)name email:(NSString *)email number:(NSString *)number
{
NSString *Name = name;
NSString *Email = email;
NSString *Number = number;
ABRecordRef newPerson = ABPersonCreate();
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, Name, NULL);
ABRecordSetValue(newPerson, kABPersonEmailProperty, Email, nil);
//ABRecordSetValue(newPerson, kABPersonLastNameProperty, @"agrawal", NULL);
//ABRecordSetValue(newPerson, kABPersonPhoneProperty, CFNu,NULL);
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, Number, kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
ABAddressBookAddRecord(_addressBook, newPerson, NULL);
BOOL saved = ABAddressBookSave(_addressBook, NULL);
if(saved == YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved" message:@"the contact has been saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" Not Saved" message:@"Not saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
There is some king of conversion conflict between NSString and const void*. How to do this conversion?? I used UTF8String too.. but it doesn't work..
Upvotes: 0
Views: 99
Reputation: 4380
You have to bridge cast in following way
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, (__bridge CFStringRef) Name, NULL);
ABRecordSetValue(newPerson, kABPersonEmailProperty, (__bridge CFStringRef) Email, nil);
Upvotes: 1