7
votes

My application has been using the QLPreviewController to display files of all types and in iOS 5.x , it seemed to do so just fine.

Now, in iOS 6.0, I get an error and it shows the controller but with a constant loading indicator and never actually loads anything.

The error in the log is: Cannot find preview item for loaded proxy: <QLPreviewItemProxy: 0x8dbf480> - file://localhost/Users/me/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/E6A58F8D-71F3-4C7A-B16E-4BA017E318E5/Documents/temp//Welcome.docx

Anyone else have this or other issues with the Quicklook in iOS 6.0? Or any suggestions of what to try? I've tried it via iPhone and iPad with both pushing the controller and presenting it.

Edit: Also just noticed that the URL in question (the one they say is bad) starts with not just file:// but file://localhost whereas the original file just started with an actual path (ie: file:///Users).

4
Just some more info: I tried checking + canPreviewItem on the fileUrl before I return it in previewItemAtIndex and it returns TRUE. So according to the Controller before it returns from that method, the url is indeed previewable....mind you that url is the one without the host in it.valheru
Another update: I tried creating a brand new project that uses the QLPreviewController. Similar circumstances and I found that the weird Proxy error still happens BUT the file displays! So now I need to figure out what's different. But the fact that the error is still there seems suspect still. Surprised more people havent experienced this.valheru

4 Answers

10
votes

Well after a bunch of research and re-creating from the ground-up a basic QuickLook viewer, I found that the error was still logged even from that BUT the documents were actually being displayed which they weren't from my original project.

I then tried putting the QLPreviewController inside a NavigationController before presenting it and ended up with the same issue. I was wrapping the QLPreviewController in a UINavigationController before presenting it because that seemed to be the way to assign the navigationItem a custom button. That worked fine in iOS 5.1 (as stated above) but apparently iOS 6.0 does not like this.

Removing the extra code that wrapped the QLPreviewController in a UINavigationController seemed to allow the document to display.

Example of controller being wrapped:

QLPreviewController* previewer = [[QLPreviewController alloc] init];
previewer.dataSource = self;
previewer.delegate = self;
[previewer setCurrentPreviewItemIndex:0];

UINavigationController* previewNavCtrl = [[UINavigationController alloc] init];
[previewNavCtrl pushViewController:previewer animated:NO];

[self presentModalViewController:previewNavCtrl animated:YES];

Change to:

QLPreviewController* previewer = [[QLPreviewController alloc] init];
previewer.dataSource = self;
previewer.delegate = self;
[previewer setCurrentPreviewItemIndex:0];

[self presentModalViewController:previewer animated:YES];

Note: again the Proxy error still seems to show up in the log however

ALSO: Any UIBarButtonItem customizations seem to no longer work without the NavigationController =/

UPDATE: I found that using fileURLWithpath to generate the fileURL for previewItemAtIndex made the original error go away. However, the same problem occurs still where the document will not load.

A new error (one I've seen other people having as well) is:

Couldn't issue file extension for path: /Users/me/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/339DDF48-AF93-41B5-B81E-A39440A131C6/Documents/temp/Welcome1.docx

FINAL UPDATE: Ok the extension issue/error was because I was trying to manually add %20 to the spaces (using [NSString stringByAddingPercentEscapesUsingEncoding] etc) when the [NSURL fileURLWithPath] must handle that already. Once I removed that, this worked and I am now on iOS 6 yay! So the real problem was nothing to do with the UINavigationController but actually the file URL being passed via previewItemAtIndex.

1
votes

I thought to answer this old question if anyone face same issue.

When you debugging an app using Xcode, each and every time the UUID of the application is changing. But this is not applicable when the app is loading from the device.

For example: I got following paths for the same app.

Document path : file:///var/mobile/Applications/CBF533A7-C19A-4336-A92C-DC1A48242A8A/Documents/ Document path : file:///var/mobile/Applications/ADB99D3B-EACA-482D-BB8A-0C12B340A044/Documents/

This can be overcome by adding following at the - (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index

NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES ) objectAtIndex:0];
NSURL *localDocumentsDirectoryURL = [NSURL fileURLWithPath:documentsDirectoryPath];
NSURL *fileURL =  [localDocumentsDirectoryURL URLByAppendingPathComponent:fileName isDirectory:NO];
return fileURL;

*fileName is just file name (medoc.pdf) where you can find on Document folder.

0
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];


}
0
votes

1)

NSMutableArray * samplepdf = [[NSMutableArray alloc]initWithObjects:@"sam1.pdf",@"sam2.pdf",@"sam3.pdf",@"sam4.pdf", nil];

//Drag the pdf file in strong textDocument Directory

2)

QLPreviewController *previewController = [[QLPreviewController alloc] init]; previewController.dataSource = self; previewController.currentPreviewItemIndex = [indexPath row]; [self presentModalViewController:previewController animated:YES];

3) #pragma mark QLPreviewControllerDataSource

// Returns the number of items that the preview controller should preview

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController {

return [samplepdf count];

}

// returns the item that the preview controller should preview

- (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)index {

NSString *documentsDirectoryPath = [[NSBundle mainBundle]resourcePath];

NSString *dataPath =[documentsDirectoryPath stringByAppendingPathComponent:[samplepdf objectAtIndex:index]];

NSURL *url = [NSURL fileURLWithPath:dataPath isDirectory:YES];  
return url;

}