I am using the code below to download a pdf file from a website and subsequently to display it in a 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]]];
all works as expected at this point but later when i use the following code to atatch the pdf file to an email using mfmailcomposer i get problems.
-(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];
}
}
this code works exactly as expected and the multi page pdf attaches as expected.
if i test the app on iPad with ios 5.0.1 sending the email to myself, when i click on the icon for the pdf in the email, the pdf doesn't open, and the preview just sits there with a uiprogress indicator spinning. however if i test the app in the same way on an ipad2 with ios 6.0.1 the pdf file opens with no problems. it also works on iphone 5 and also on mac with mountain lion.
so whats happening? can anyone tell me whats wrong with my code and implementation to give me this strange behaviour on ipad 1 but not on ipad 2 etc.
please advise
thanks
I finally figure this out and solved the problem by changing my code as follows
fileName = [selectedSizeToUse stringByAppendingString:@".pdf"];
[mailController setSubject:selectedSizeToUse];
[mailController addAttachmentData:fileToAtatch mimeType:@"application/pdf" fileName:fileName];
seems that for ios5 implementations pdf files need the .pdf extension to be recognised in the preview application, while in iOS 6 implementations the preview app was clever enough to display the pdf without the .pdf extension.
hope this helps somebody else that got stuck