objective-cios6qlpreviewcontroller

QLPreviewController not working in iOS 6


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

Solution

  • 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];
    
    
    }