在我的应用程序中,我想在 MFMailComposeViewController 中添加 .vcf 文件作为附件。
问问题
2112 次
2 回答
3
MFMailComposeViewController的文档显示其addAttachmentData:mimeType:fileName:实例方法是要走的路:
- (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename
附件是加载或转换为 NSData 的实际 vcf 文件。
vcf的mimeType是@"text/x-vcard"。
文件名是您想调用的任何名称,但您应该使用 .vcf 扩展名以确保电子邮件程序能够理解它。
于 2010-11-29T11:17:01.680 回答
3
使用以下代码创建一个 vcf 文件并将其保存在目录中。
ABAddressBookRef addressBook = ABAddressBookCreate();
//-------------------Creating and saving vcf --------------------------------
CFArrayRef contacts = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFDataRef vcards = (CFDataRef)ABPersonCreateVCardRepresentationWithPeople(contacts);
NSString *vcardString = [[NSString alloc] initWithData:(NSData *)vcards encoding:NSUTF8StringEncoding];
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *folderPath = [paths objectAtIndex:0];
NSString *filePath = [folderPath stringByAppendingPathComponent:@"contacts.vcf"];
[vcardString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
NSLog(@"Documents directory: %@",[fileMgr contentsOfDirectoryAtPath: folderPath error:&error]);
if (addressBook) {
CFRelease(addressBook);
}
于 2013-07-03T11:37:53.443 回答