IOS 6.0 Quicklook QLPreviewController errors with: "Cannot find preview item for loaded proxy"

My application uses QLPreviewController to display files of all types and in iOS 5.x, it seems like this is just fine.

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

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

Does anyone have any problems with Quicklook in iOS 6.0? Or any suggestions on what to try? I tried it through the iPhone and iPad, clicking on the controller and presenting it.

Edit: They also noticed that the URL in question (the one they say is bad) starts not only with the file: //, but with the file: // localhost, while the original file only starts with the actual path (i.e. : file: /// Users).

+6
source share
4 answers

Well, after doing some research and recreating from scratch the main QuickLook observer, I found that the error was still logged even from that moment, but in fact documents were displayed that they were not from my original project.

Then I tried putting the QLPreviewController inside the NavigationController before presenting it, and ended up getting the same problem. I wrapped the QLPreviewController in a UINavigationController before presenting it, because it seemed to be a way to assign navigationItem to a custom button. This works fine in iOS 5.1 (as mentioned above), but iOS 6.0 doesn't seem to like it.

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

Controller Wrapping Example:

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 appears in the log, however

ALSO: any UIBarButtonItem settings don't seem to work anymore without NavigationController = /

UPDATE: I found that using fileURLWithpath to generate the url file for previewItemAtIndex made the original error go away. However, the same problem occurs when the document does not load.

New bug (I also saw other people):

Failed to 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 problem / error was caused because I tried to manually add% 20 to spaces (using [NSString stringByAddingPercentEscapesUsingEncoding] etc.) when [NSURL fileURLWithPath] should handle this already. As soon as I deleted it, it worked, and I'm now on iOS 6 yay! Thus, the real problem was not related to the UINavigationController, but in fact the file URL was passed through previewItemAtIndex.

+10
source

I thought to answer this old question if someone is facing the same problem.

When debugging an application using Xcode, every time the UUID of the application changes. But this does not apply when the application is downloaded from the device.

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

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 the following to - (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 the file name (medoc.pdf) that you can find in the Document folder.

+1
source

I downloaded the file from a remote URL and saved locally, then I display the PDF using QLPreviewController. In iOS 6 it works.

First, I saved the file from a 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
source

1)

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

// Drag the pdf file to the strong textDocument directory

2)

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

3) #pragma mark QLPreviewControllerDataSource

// Returns the number of elements that the preview should preview.

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

return [samplepdf count];

}

// returns the item that should preview the 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; 

}

0
source

Source: https://habr.com/ru/post/926864/


All Articles