将电子邮件附加到电子邮件的mfmailcomposer无法使用ipad 1,但可以使用ipad2

时间:2013-01-27 19:38:52

标签: pdf email-attachments mfmailcomposeviewcontroller

我使用以下代码从网站下载pdf文件,然后在uiwebview中显示

NSString *url = [NSString stringWithString:[[[popOverContent currentValues]     objectAtIndex:0]objectForKey:@"Web"]];

    // Determile cache file path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,      NSUserDomainMask, YES);
    NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.pdf"];

    // Download and write to file
    NSURL *url2 = [NSURL URLWithString:url];
    NSData *urlData = [NSData dataWithContentsOfURL:url2];
    [urlData writeToFile:filePath atomically:YES];

    fileToAtatch = urlData;

    // Load file in UIWebView
    [self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];

此时所有工作都按预期进行,但后来当我使用以下代码使用mfmailcomposer将pdf文件发送到电子邮件时,我遇到了问题。

-(IBAction)EmailPressed:(id)sender
{
if ([MFMailComposeViewController canSendMail]) {

    MFMailComposeViewController *viewController = [[MFMailComposeViewController alloc] init];
    viewController.mailComposeDelegate = self;
    NSString *query = @"please find atatched the requested data sheet";
    [viewController setSubject:[popOverContent selectedSize]];
    [viewController setMessageBody:query isHTML:NO];
    [viewController addAttachmentData:fileToAtatch mimeType:@"application/pdf" fileName:[popOverContent selectedSize]];
    [self presentModalViewController:viewController animated:YES];

}

}

此代码完全按预期工作,多页pdf按预期附加。

如果我在iPad上用ios 5.0.1测试应用程序发送电子邮件给自己,当我点击电子邮件中的pdf图标时,pdf没有打开,预览只是坐在那里有一个uiprogress指示器旋转。 但是,如果我在ipad2上使用ios 6.0.1以相同的方式测试应用程序,则pdf文件打开没有任何问题。 它也适用于iphone 5以及带有山狮的Mac。

所以发生什么事了? 任何人都可以告诉我,我的代码和实现有什么问题,在ipad 1上给我这个奇怪的行为但不在ipad 2上等。

请告知

感谢

1 个答案:

答案 0 :(得分:1)

我终于解决了这个问题并通过更改我的代码解决了这个问题,如下所示

         fileName = [selectedSizeToUse stringByAppendingString:@".pdf"];
         [mailController setSubject:selectedSizeToUse];
         [mailController addAttachmentData:fileToAtatch mimeType:@"application/pdf" fileName:fileName];

似乎对于ios5实现,pdf文件需要在预览应用程序中识别.pdf扩展名,而在iOS 6实现中,预览应用程序非常聪明,可以显示没有.pdf扩展名的pdf。

希望这可以帮助其他人陷入困境

相关问题