iphone - 如何使用地址簿联系人详细信息在 iPhone 中生成 vcard?

标签 iphone objective-c ios vcf-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,我建议使用以下伪代码:

  1. 获取联系人照片作为 NSData (contactlist.objContact.Photo)
  2. 将 NSData 字节转换为 BASE 64 编码方案(NSData to base64base64EncodedString)
  3. 将编码数据和属性添加到 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/

相关文章:

iphone - 如何安全地删除 iOS 中的文件?

iphone - 如何在 iphone 中检查单元格是否有 subview ?

c++ - 从 Byte * 到 unsigned int 的 memcpy 是反转字节顺序

iOS 9 解析JSON的最佳方案

ios - 如何存储字典数组并将其显示在 swift 4 的 Collection View 中

iPhone 4 对象标签中的 Google map 显示问题

iphone - 在 ios 中隐藏 UINavigationBar 的问题

c# - 带有左右页面预览的 UIScrollView

objective-c - Cocoa - 内存问题 - NSTableView

ios - 如何在 SpriteKit 中获得类似于 peek 或 pop 的 3d touch 应用程序图标触觉反馈