首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用addressBook框架在AddressBook中保存名称和电子邮件

无法使用addressBook框架在AddressBook中保存名称和电子邮件
EN

Stack Overflow用户
提问于 2013-12-20 14:23:58
回答 1查看 94关注 0票数 0

在我的应用程序中,我试图保存姓名和联系人号码以进行通讯录。

但是,当保存(使用下面的代码)时,我得到了错误:

代码语言:javascript
复制
/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

我使用的代码是:

代码语言:javascript
复制
-(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];
    }
}

在NSString和const之间存在着一些转换冲突的国王。如何进行转换??我也用UTF8String ..。但不管用..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-20 14:54:22

你必须按以下方式架设桥梁

代码语言:javascript
复制
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, (__bridge CFStringRef) Name, NULL);
ABRecordSetValue(newPerson, kABPersonEmailProperty, (__bridge CFStringRef) Email, nil);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20705708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档