UIDocumentInteractionController for Remote PDF Files

Does anyone know how to use UIDocumentInteractionController for remote PDF files "Open in iBooks", I can not get around this. I managed to open my pdf file in QLPreviewController and get OptionsMenu to allow me to open in iBooks, but I will not open the file if it is deleted ... when I use the local file, it works fine.

If this is not possible, then what is the alternative?

Thanks in advance

+3
source share
2 answers

Although it UIDocumentInteractionControllerhas a convenience method interactionControllerForURL:, the argument must be the file URL for this. Thus, you either upload the PDF file to your application, or open it using an object, UIDocumentInteractionControlleror you can use the object UIWebViewto open deleted PDF files. Pass in the URL of the web view and they just open.

+3
source

The ad mentioned that you must use the file url for the UIDOcumentInteractionController. Download the document first. A very easy way to do this is AFNetworking . This is how I use AFNetworking to upload a file:

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)req navigationType:(UIWebViewNavigationType)navigationType {
self.title = req.URL.description;

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

NSURL *URL = req.URL;
NSURLRequest *request = [NSURLRequest requestWithURL:URL];

NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
    NSURL *documentsDirectoryPath = [NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]];
    self.fileURLPath = [documentsDirectoryPath URLByAppendingPathComponent:[response suggestedFilename]];
    return self.fileURLPath;
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
    NSLog(@"File downloaded to: %@", filePath);
}];
[downloadTask resume];


return YES;

}

Now that you have the urlpath file, you can create a UIDocumentInteractionController as follows:

documentController = [UIDocumentInteractionController interactionControllerWithURL:self.fileURLPath];
0
source

All Articles