[Cocoa]_[初级]_[vcf文件的生成和导出]

之前对vcf文件一点都不理解,通过学习vcf的相关资料,对此进行了实例验证。

对文件进行写入数据:

-(void) doSaveVcfFile:(NSString*) filepath cardData:(id) data
{
    FILE *write =fopen([filepath UTF8String], "w");
    if (write == nil)
    {
        return;
    }
    const char *buff =[self doSaveVcf:data];
    fwrite(buff, strlen(buff), 1, write);
    fclose(write);

}

vcf文件:

BEGIN:VCARD
FN:某某某
ORG:XXX科技有限公司;
NOTE;ENCODING=QUOTED-PRINTABLE:研发
TEL;HOME:13632984598
X-IM;QQ:1766567812
EMAIL;PREF:[email protected]
ADR;HOME:;; 福田区 泰然九路 海松大厦A座;深圳市;中国 广东省;513800;;
STARRED:false
UID:2053
VERSION:3.0
REV:20140904
END:VCARD
vcf文件代码实现部分:

 -(const char *) doSaveVcf
{
 
    NSString *fileHead =@"BEGIN:VCARD\r\n";
    NSString *fileEnd =@"END:VCARD\r\n";
    fileHead =[fileHead stringByAppendingFormat:@"UID:5312\r\n",id];
    fileHead =[fileHead stringByAppendingFormat:@"VERSION:%@\r\n",[ProductUtil getProductVersion]];
    fileHead =[fileHead stringByAppendingString:@"REV:20140904\r\n"];
    fileHead =[fileHead stringByAppendingString:@"FN:某某某\r\n"];
    fileHead =[fileHead stringByAppendingString:@"NOTE;ENCODING=QUOTED-PRINTABLE:研发\r\n"];
    fileHead =[fileHead stringByAppendingString:@"TEL;HOME:13632984598\r\n"];
    fileHead =[fileHead stringByAppendingString:@"EMAIL;PREF:[email protected]\r\n"];
    fileHead =[fileHead stringByAppendingString:@"ADR;HOME:;; 福田区 泰然九路 海松大厦A座;深圳市;中国 广东省;513800;;\r\n"];
    fileHead =[fileHead stringByAppendingString:@"STARRED:false\r\n"];
    fileHead =[fileHead stringByAppendingString:@"\r\n"];
    fileHead =[fileHead stringByAppendingFormat:@"%@\r\n",fileEnd];

    return [fileHead UTF8String];
    
    }

以上只是一个简单的vcf文件的实现,实现的是静态的效果,只是对vcf知识学习的一个小结。


你可能感兴趣的:(Cocoa)