QuickLook Thumbnailing

RSS for tag

Generate thumbnails for common file types and add a Thumbnail Extension to your app using QuickLook Thumbnailing.

Posts under QuickLook Thumbnailing tag

12 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

QLPreviewController Blinks on Previewing Some PDF files
QLPreview keeps blinking and stops previewing the file when opening some high-resolution PDF files with heavy content. This can only be simulated in a real device built in xcode simulators cant simulate the issue. Tested in Xcode Version 15.4 (15F31d) and iPadOS Version 17.5.1. Following is My Sample code : import UIKit import QuickLook class ViewController: UIViewController { var currentViewFilePath = "" let preview = QLPreviewController() override func viewDidLoad() { super.viewDidLoad() self.setupQLPreview() loaddata() // Do any additional setup after loading the view. } func loaddata(){ if let fileURL = Bundle.main.url(forResource: "CD28048D", withExtension: "pdf") { self.currentViewFilePath = fileURL.relativePath self.preview.reloadData() // Use the fileURL here print("File URL: \(fileURL)") } else { print("File not found") } } } extension ViewController:QLPreviewControllerDelegate,QLPreviewControllerDataSource{ func setupQLPreview(){ preview.delegate = self preview.dataSource = self self.view.addSubview(preview.view) let previewhight = (UIScreen.main.bounds.height - ((self.navigationController?.navigationBar.frame.height ?? 0))) preview.view.translatesAutoresizingMaskIntoConstraints = false preview.view.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true preview.view.leftAnchor.constraint(equalTo: self.view.leftAnchor,constant: 4).isActive = true preview.view.rightAnchor.constraint(equalTo: self.view.rightAnchor,constant: -4).isActive = true preview.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor,constant: 4).isActive = true preview.view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor,constant: -4).isActive = true preview.view.widthAnchor.constraint(equalToConstant: self.view.frame.width-8).isActive = true preview.view.heightAnchor.constraint(equalToConstant: previewhight-4).isActive = true preview.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true preview.navigationController?.isNavigationBarHidden = true self.addChild(preview) preview.didMove(toParent: self) } func numberOfPreviewItems(in controller: QLPreviewController) -> Int { if self.currentViewFilePath.isEmpty || self.currentViewFilePath == ""{ return 0 }else{ return 1 } } func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem { let fileUrl = URL(fileURLWithPath: self.currentViewFilePath) return fileUrl as QLPreviewItem } } while running the above code Xcode debugger prints following errors: View service did terminate with error: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted} #Remote Preview collection viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted} #Remote [u 0AA9D4C5-BBA1-56F6-8FFF-F5F56B99399A:m (null)] [com.apple.quicklook.extension.previewUI(1.0)] Connection to plugin invalidated while in use.
0
0
134
2w
How to stop Finder from triggering full file download of a file on network share to generate the thumbnail
Default behaviour of the macOS when interacting via Finder with a network share is to create thumbnails to provide a nice user experience. This behaviour is implemented by QuickLook framework. This triggers the full file download and quickly lead to cache using large disk space and even cache trashing. We can disable QuickLook selectively by injecting specially prepared .DS_Store file with instruction/setup to disable thumbnails in that directory but still degrades user's experience only in the network share ecosystem. Is there any way we can provide our own thumbnails or ask Finder to not download full file to generate the thumbnail?
1
0
257
3w
Accesing Files in Thumbnail Extension and Quick Look Extension
I am developing Thumbnail Extension. To prepare a graphic (in .dylib) for file specified in URL.path I need to access second file, which has the same filename, but different extension. For example, I have "data" in file.*** and "colors" in file.yyy. Is it possible to read data from this second file while processing the first file in my extension? In my current implementation it sometimes works, but most of the time it doesn't work - it is not possible to read data from file.yyy when preparing thumbnail for file.***, causing exception in my .dylib routine. Is there some setting which would allow me to do this?
0
0
170
Jun ’24
QLSupportedContentTypes cannot contain system-supported types (UTIs)
Hi folks, My app is reading proprietary files with the file name extension .JPX - which is out of my control. In addition I’m providing QuickLook and Thumbnail extensions, used system-wide and in my app. Unfortunately iOS is assigning the JPEG-2000 file type (UTI „public.jpeg-2000“) to this file extension, and therefore - to work with associated files - my app is importing this UTI and both extensions are listing „public.jpeg-2000“ in their info.plist as QLSupportedContentTypes. This works to some extent in simulators and when debugging from Xcode on a device: Files with the file extension „.JPX“ are listed with thumbnails provided by my extension, although the preview seems to invoke the system-provided viewer and fails. Not perfect, but good enough as my app requires an icon preview (aka thumbnail) in its UIDocumentBrowserViewController. But when I try to submit my app incl. extensions to the Apple App Store / TestFlight asset validation is reporting an error: „Asset validation failed. Invalid Info.plist value. The value for the key ‚QLSupportedContentTypes‘ in bundle … is invalid. [public.jpeg-2000] are system-supported types.“ How to assign QuickLook / Thumbnail extensions to 3rd party files types whose extension is conflicting with a system-supported UTI? I just spent one of my TSIs for this question - as my Apple developer membership is renewed shortly - but maybe this community as some smart tip to share... Appreciate any help, Mattes
1
0
579
Feb ’24
Embed external binary in QuickLook Preview application
Hello, I am trying to write a simple QuickLook generator, which takes a file, runs an external binary to produce the data, and then creates and shows an image in a preview. The input files are uncommon data formats, and the binary in this case converts these to PNG. I have tried multiple methods and followed many discussions on these forums and StackOverflow, but unfortunately I am yet to get it working. That said, the program I have builds and runs using the qlmanage tool, however when running in Finder or on the server qlmanage -x the program fails. As I understand, it when using QuickLook in Finder it calls the QuickLook daemon quicklookd which is also called when using the qlmanage -x CLI command, but please correct me if I am wrong about this. The basic idea for all generator functions is: create NSTask or Process and run the third-party binary, using the requested file path as input run the task, pipe output, and read output convert the piped output to NSImage show image Attempt 1 (old-style qlgenerator plugin in Obj-C): Initially I tried adding the binary as an asset to the QuickLook Preview target and the generator would work as mentioned using qlmanage, however it would not work using qlmanage -x or from Finder. Here is the preview function: OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) { NSLog(@"QuickLook plugin started"); NSInteger width = 512; NSURL *fileURL = (__bridge NSURL *)url; NSString *escapedFilePath = [fileURL.path stringByReplacingOccurrencesOfString:@" " withString:@"\\ "]; NSLog(@"Original Path: %@", fileURL.path); NSLog(@"Escaped Path: %@", escapedFilePath); NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.pjharrison.qlgwyddion"]; NSURL *nsURLExecutable = [bundle URLForAuxiliaryExecutable:@"gwyddion-thumbnailer"]; if (nsURLExecutable) { // The resource was found, and nsURLData is not nil. // Proceed with using nsURLData. NSLog(@"Resource 'gwyddion-thumbnailer' found in the bundle."); } else { // The resource was not found. Handle the situation accordingly. NSLog(@"Resource 'gwyddion-thumbnailer' not found in the bundle."); } NSTask *task = [[NSTask alloc] init]; NSLog(@"Pathhhh %@", nsURLExecutable.path); [task setExecutableURL:nsURLExecutable]; [task setArguments:@[@"kde4", [@(width) stringValue], escapedFilePath]]; NSLog(@"Task set"); NSString *argumentString = [task.arguments componentsJoinedByString:@" "]; NSLog(argumentString); NSPipe *pipe = [NSPipe pipe]; NSFileHandle *file = pipe.fileHandleForReading; [task setStandardOutput:pipe]; NSLog(@"Pipe set"); [task launch]; NSLog(@"Task launched"); NSData *data = [file readDataToEndOfFile]; NSLog(@"Got data"); [task waitUntilExit]; NSLog(@"Task completed"); NSInteger taskStatusCode = [task terminationStatus]; NSLog(@"Task finished with status code %ld", taskStatusCode); NSString *dataLength = [NSString stringWithFormat:@"%lu", data.length]; NSLog(dataLength); CGDataProviderRef imageDataProvider = CGDataProviderCreateWithCFData((CFDataRef)data); CGImageRef cgImage = CGImageCreateWithPNGDataProvider(imageDataProvider, NULL, true, kCGRenderingIntentDefault); if (cgImage) { CGFloat height = CGImageGetHeight(cgImage); CGFloat width = CGImageGetWidth(cgImage); CGSize size = CGSizeMake(width, height); // Preview will be drawn in a vectorized context CGRect rect = CGRectMake(0, 0, width, height); CGContextRef cgContext = QLPreviewRequestCreateContext(preview, size, true, NULL); CGContextDrawImage(cgContext, rect, cgImage); NSLog(@"Image drawn"); QLPreviewRequestFlushContext(preview, cgContext); NSLog(@"Flushed"); // release resources if (cgContext) { CFRelease(cgContext); NSLog(@"Context released"); } CGImageRelease(cgImage); NSLog(@"Image released"); } else { NSLog(@"cgImage is NULL"); } return noErr; } Inspection console logs would give various Operation not permitted errors when run from the quicklookd server. I suspect that possibly this is due to App Sandboxing issues. Attempt 2 After coming across various articles online by @eskimo and others, including the official docs and various other posts, I have tried to sign the binary executable as described in the documentation and embed it in the project. Unfortunately after signing the app I have not been able to get the executable to run. When called from the QuickLook Preview function, the process returns with an error code. Perhaps the issue is here and the executable has not been signed properly? Attempt 3 I have also tried to create a Swift-based app and add a QuickLook Extension to the app (creating an app with a .appex) using a similar flow as tried in Attempt 1. Also no luck here so far. At this point I am stuck and would appreciate any help or pointers! Many thanks in advance.
0
0
473
Feb ’24
Quick looks not working with old configuration/ code.
Hello, I am experiencing an issue with a piece of JavaScript code that I use for triggering Quick Look on iOS devices. This functionality was working fine until the recent non-beta updates of iOS 17. It still functions as expected on older iOS versions and some beta versions of iOS 17, but not on the latest update. Here's the original code snippet: anchor.setAttribute('rel', 'ar'); anchor.appendChild(document.createElement('img')); anchor.setAttribute("id", "charpstar"); return (usdzSrc) => { anchor.setAttribute('href', usdzSrc + "#allowsContentScaling=0"); anchor.click(); }; With this code, the Quick Look feature used to work directly without navigating to an intermediary page. However, after the update, it ceased functioning. The error I am getting is "Object needs new version of iOS" To troubleshoot, I modified the code as follows: anchor.href = `${realityFileUrl}#allowsContentScaling=0`; anchor.addEventListener('click', (event) => { event.preventDefault(); window.open(anchor.href, '_blank'); }); // Append the anchor element to the document body. document.body.appendChild(anchor); // Click the anchor element to open the .reality file. anchor.click(); This revised approach does open the file, but it first navigates to an intermediary page, which is not acceptable for our client's user experience. Could you provide guidance on how to resolve this issue? Specifically, I'm looking for a way to use Quick Look on iOS 17 (non-beta versions) without being redirected to an intermediary page. Any insights or updates regarding changes in iOS 17 that might affect this functionality would be greatly appreciated. Thank you for your assistance.
0
0
369
Nov ’23
Should I register(?) my app extension?
Hi, I'm developing quick look extensions of my app's custom files to display previews and thumbnails in the finder. When I developed and debugged these extensions, they were listed on the "added extensions" in the System Settings > Privacy and Security > Extensions. And They worked. But, they don't appear on the list when I made a package and install it on my mac or testing machine. And the quick look didn't work at all. Should I configure build settings or packaging options to make them register(?) or work?
0
0
461
Nov ’23
macOS app rejected for Thumbnail extension continuing to run
I received a rejection for "Your app spawns processes that continue running after the user has quit the app." The process in question is the app's Thumbnail extension. When I remove all of my own code from the thumbnail extension, it still continues to run after I exit my app. This is the entirety of the extension's code, which now renders blank thumbnails: import QuickLookThumbnailing class ThumbnailProvider: QLThumbnailProvider { override init() { } override func provideThumbnail(for request: QLFileThumbnailRequest, _ handler: @escaping (QLThumbnailReply?, Error?) -> Void) { let reply = QLThumbnailReply(contextSize: request.maximumSize) { (context: CGContext) -> Bool in return true } handler(reply, nil) } } Presumably Thumbnail extensions continue to run so that Finder (among others) can generate thumbnails as necessary. AFAIK, I have no direct control over the extension's lifecycle. Is this just App Review's mistake? The "Next Steps" are clueless: "You can resolve this by leaving this option unchecked by default, providing the user the option to turn it on." The app uses its own thumbnail extension to render thumbnails for document templates, which may be an uncommon thing.
1
0
808
Aug ’23