iphoneiosvcf-vcardemail-attachmentsmfmailcomposer

Can't find vcard attachment with the mail


I am trying to send an email from my iphone, with a vcard as attachment. When I am sending the mail, the vcard is being attached with the mail. But the receiver of the mail can't find the vcard attachment. Help needed. This is the code I have used

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];

Thanks


Solution

  • I found the solution... Isubmitted a bug on Apple radar about it. MFMailcomposer has a bug in which you have to send an image along with your extra attachments in order to get the weird items like a pdf to work... try this and replace the pdf with your card:

    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];