我的代码在这里:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Downloading Started");
NSURL *url = [NSURL URLWithString:urlToDownload];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,strFileName];
//saving is done on main thread
dispatch_async(dispatch_get_main_queue(), ^{
[urlData writeToFile:filePath atomically:YES];
NSLog(@"File Saved !");
[self openDocumentIn:filePath];
});
}
});
- (void)openDocumentIn:(NSString*)path {
[self dismissViewControllerAnimated:YES completion:nil];
controller = [[UIDocumentInteractionController alloc] init];
controller.URL = [NSURL fileURLWithPath:path];
controller.delegate = self;
controller.UTI = @"com.adobe.pdf";
[controller presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
}
上面的代码在 iPhone 上可以正常工作,但在 iPad 上却不行。