我正在使用下面的代码从网站下载 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 按预期附加。
如果我使用 ios 5.0.1 在 iPad 上测试应用程序,将电子邮件发送给自己,当我单击电子邮件中 pdf 的图标时,pdf 不会打开,并且预览只是坐在那里,uiprogress 指示器在旋转。但是,如果我在带有 ios 6.0.1 的 ipad2 上以相同的方式测试应用程序,则 pdf 文件将毫无问题地打开。它也适用于 iphone 5 和带有山狮的 mac。
那么发生了什么?谁能告诉我我的代码和实现有什么问题,让我在 ipad 1 上出现这种奇怪的行为,但在 ipad 2 等上却没有。
请指教
谢谢