【问题标题】:Show actual file icon in macOS Quicklook Preview在 macOS Quicklook 预览中显示实际文件图标
【发布时间】:2021-02-07 11:06:40
【问题描述】:

我正在为我的应用程序编写 QuickLook 扩展程序,并且我希望能够显示特定文件的实际图标图像,如 Finder 中所示。我已经尝试为此使用 QLThumbnailGenerator,但它总是会返回一个纯白色的文档图标。

QLThumbnailGenerationRequest *request = [[QLThumbnailGenerationRequest alloc] initWithFileAtURL:url size:size scale:scale representationTypes:QLThumbnailGenerationRequestRepresentationTypeIcon];

QLThumbnailGenerator *generator = [QLThumbnailGenerator sharedGenerator];

__unsafe_unretained PreviewViewController *weakSelf = self;

[generator generateBestRepresentationForRequest:request completionHandler:^(QLThumbnailRepresentation *thumbnail, NSError *error) {
    dispatch_async(dispatch_get_main_queue(), ^{
        if (thumbnail == nil || error) {
            NSLog(@"Failed to generate thumbnail! %@", error);
            // Handle the error case gracefully
        } else {
            // Display the thumbnail that you created
            NSLog(@"Generated thumbnail!");
            weakSelf.imageView.image = thumbnail.NSImage;
        }
    });
}];

原码here.

【问题讨论】:

    标签: macos quicklook


    【解决方案1】:

    这更像是一种解决方法,但改用iconForFile 方法,即_imageView.image = [[NSWorkspace sharedWorkspace] iconForFile:url.path] 可以满足我的要求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多