找不到邮件的vcard附件

时间:2011-12-12 06:28:07

标签: iphone ios vcard email-attachments mfmailcomposer

我正在尝试从我的iphone发送电子邮件,附带vcard作为附件。当我发送邮件时,vcard附有邮件。但是邮件的接收者找不到vcard附件。需要帮助。 这是我用过的代码

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource:@"Vcard" ofType:@"vcf"];
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [picker addAttachmentData:myData mimeType:@"text/x-vcard" fileName:@"Vcard.vcf"];
    [picker setMessageBody:emailBody isHTML:NO];
    [self presentModalViewController:picker animated:YES];
    [picker release];

由于

1 个答案:

答案 0 :(得分:2)

我找到了解决方案......在Apple雷达上提交了一个关于它的错误。 MFMailcomposer有一个错误,你必须发送一个图像和你的额外附件,以获得像pdf这样的奇怪项目...尝试这个并用你的卡替换pdf:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
NSString *emailSubject = [NSString localizedStringWithFormat:@"MedicalProfile"];
[controller setSubject:emailSubject];


NSString *fileName = [NSString stringWithFormat:@"%@.pdf", profileName];
NSString *saveDirectory = NSTemporaryDirectory();
NSString *saveFileName = fileName;
NSString *documentPath = [saveDirectory stringByAppendingPathComponent:saveFileName];  

*** YOU MUST INCLUDE AN IMAGE OR THE PDF ATTATCHMENT WILL FAIL!!!***
// Attach a PDF file to the email 
NSData *pdfData = [NSData dataWithContentsOfFile:documentPath];    
[controller addAttachmentData:pdfData mimeType:@"application/pdf" fileName:fileName];


// Attach an image to the email
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"miniDoc" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
[controller addAttachmentData:imageData mimeType:@"image/png" fileName:@"doctor"];


[controller setMessageBody:[NSString stringWithFormat:@"%@'s Medical Profile attatched!", profileName] isHTML:NO];

[self presentModalViewController:controller animated:YES];
controller.mailComposeDelegate = self;
[controller release];