我有一个应用程序,我想将地址簿详细信息导入 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 ...
关于iphone - 如何使用地址簿联系人详细信息在 iPhone 中生成 vcard?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14039364/