将 pdf 附加到电子邮件不会从 iOS 应用内发送 pdf

Attaching pdf to email does not send pdf from within iOS app

我有一个 iOS 应用程序应该允许用户 select 一个 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];
}

代码正确。您应该检查文件名。它是有效的字符串(文件名)吗? presentModalViewController 也已弃用。你应该使用 presentViewController:animated:completion。在设备上检查这个,而不是在模拟器上。