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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With