2011-12-12 90 views
0

我正嘗試從我的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

我找到了解決辦法... Isubmitted蘋果雷達關於它的錯誤代碼。 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];