我有一个iOS应用程序,应该允许用户选择一个pdf文件并通过那里的电子邮件帐户发送它,我有以下代码向用户显示电子邮件并显示附加的pdf,但是电子邮件是发送pdf未附加到收到的电子邮件中。
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Public Holidays"];
NSString *plistFilePath = [[NSBundle mainBundle] pathForResource:currentCountry ofType:@"pdf"];
NSData *myData = [[NSFileManager defaultManager] contentsAtPath:plistFilePath];
[picker addAttachmentData:myData mimeType:@"application/pdf" fileName:currentCountry];
// Fill out the email body text
NSString *emailBody = @"Attached to this email is the PDF bought";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
答案 0 :(得分:0)
代码是正确的。你应该检查文件名。它是一个有效的字符串(文件名)。也不推荐使用presentModalViewController。你应该使用presentViewController:animated:completion。在设备上检查,而不是在模拟器上。