11
votes

In iOS 6 the QLPreviewController no longer loads a PDF from a URL. It works fine in iOS 5. I have implemented the QLPreviewControllerDataSource methods as documented here.

#pragma mark - QLPreviewControllerDataSource
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
    return 1;
}

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index;
{
    NSURL *fileURL = [NSURL URLWithString:@"http://www.bliley.net/XTAL/PDF_Instructions/Test_File.pdf"];
    return fileURL;
}

This works perfectly in iOS 5, however in iOS 6 the console outputs:

Couldn't issue file extension for path: /XTAL/PDF_Instructions/Test_File.pdf
4
Doesn't it actually require using a local file URL? It looks to me like you are using a remote url and it's erroring with everything after the host portion.valheru
someone told me that in ios 6 they implemented a stricter check for this method that the url most start with 'file://', but I can't find any documentations on it. If anyone knows of a reference, please post.MikeIsrael
Did you find a solution? if so please share it or accept an answer. ThanksDaniel Benedykt

4 Answers

8
votes

Have you tried using fileURLWithPath instead of URLWithString? I had other issues that were fixed by doing so.

Also not sure if QLPreviewController will handle remote URLs. If not, you could download the file and then display it.

7
votes

I downloaded the file from remote url and saved locally, then I display the PDF using the QLPreviewController .In iOS 6 its working.

First i saved the file from remote url using the following code :

    NSString *local_location;

    NSString *path = [[NSBundle mainBundle] pathForResource:@"sampleData" ofType:@"plist"];
        path = NSTemporaryDirectory();
    local_location= [path stringByAppendingPathComponent:[NSString stringWithFormat:@"My_Invoice.pdf"]];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString: remoteurl]];
        [request setDownloadDestinationPath:local_location];
        [request startSynchronous];

For showing the Pdf :

QLPreviewController* preview = [[QLPreviewController alloc] init];
        preview.dataSource = self;
        [self presentModalViewController:preview animated:YES];

QLPreviewController delegate methods are :

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
    return 1;
}

- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{

    return [NSURL fileURLWithPath:local_location];


}
4
votes

I am having a similar issue and seems like it might stem from a stricter enforcement of the file-type URL of QLPreviewItem

@property (readonly) NSURL *previewItemURL;
Discussion
This property is used by a Quick Look preview controller to get an item’s URL. In typical use, you would implement a getter method in your preview item class to provide this value.

The value of this property must be a file-type URL.

If the item is not available for preview, this property’s getter method should return nil. In this case, the Quick Look preview controller displays a “loading” view.

Availability
Available in iOS 4.0 and later.
Declared In
QLPreviewItem.h

UPDATE: I have opened a bug with Apple dealing with this issue for iOS 6 and it seems they have aced it as a bug so may offer a fix in the near future. The bug I opened had to do with using custom NSURLProtocols for the preview, but may apply to other aspects as well.

Link to class

0
votes

But note that QLPreviewController expects a URL to a local resource

You would need to download and save the PDF file locally first and then create a proper file URL to the local file.