如何使用地址簿联系方式在iPhone中生成vcard?

我有一个应用程序,我想将地址簿详细信息导入vcard格式.这是我已经完成的代码,但问题是我的电子邮件地址,照片,组织名称等没有保存在vcard中.

    -(NSString*)vcardrepresentation
{


        NSMutableArray *mutableArray = [[NSMutableArray alloc] init];

        [mutableArray addObject:@"BEGIN:VCARD"];
        [mutableArray addObject:@"VERSION:3.0"];

        [mutableArray addObject:[NSString stringWithFormat:@"FN:%@ %@", self.contactlist.objContact.firstname,self.contactlist.objContact.lastname]];

        [mutableArray addObject:[NSString stringWithFormat:@"ORG:%@",self.contactlist.objContact.companyname]];
        [mutableArray addObject:[NSString stringWithFormat:@"ADR:%@",self.contactlist.objContact.City]];

        if ([phoneArray count]!=0)
            [mutableArray addObject:[NSString stringWithFormat:@"TEL:%@", phoneemail.phoneNumber]];

        if ([emailArray count]!=0)
        {
            [mutableArray addObject:[NSString stringWithFormat:@"EMAIL:%@",phoneemail.phoneNumber]];
        }
    if ([contactlist.objContact.Photo length]==0)
    {
        [mutableArray addObject:[NSString stringWithFormat:@"PHOTO:%@",[UIImage imageNamed:@"man.png"]]];
    }
    else
    {

        [mutableArray addObject:[NSString stringWithFormat:@"PHOTO:%@",[UIImage imageWithData:contactlist.objContact.Photo]]];
    }


        [mutableArray addObject:@"END:VCARD"];

        NSString *string = [mutableArray componentsJoinedByString:@"\n"];


        return string;

}

如何以vcard格式保存所有联系人数据?

最佳答案 Rani,我建议使用以下伪代码:

>获取NSData联系人照片(contactlist.objContact.Photo)
>将NSData字节转换为BASE 64编码方案(NSData to base64,base64EncodedString)
>将编码数据和属性添加到vCard:

[mutableArray addObject:[NSString stringWithFormat:@“PHOTO; ENCODING = BASE64; TYPE = JPEG:%@”,data]];

对于您的信息vCard photographs是使用Base 64方案编码的图像.有16种支持的文件格式,包括GIF和JPEG.这是一个例子:

PHOTO;ENCODING=BASE64;TYPE=GIF: 
    R0lGODdhfgA4AOYAAAAAAK+vr62trVIxa6WlpZ+fnzEpCEpzlAha/0Kc74+PjyGM 
    SuecKRhrtX9/fzExORBSjCEYCGtra2NjYyF7nDGE50JrhAg51qWtOTl7vee1MWu1 
    50o5e3PO/3sxcwAx/4R7GBgQOcDAwFoAQt61hJyMGHuUSpRKIf8A/wAY54yMjHtz 
    ...
点赞