【发布时间】: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.
【问题讨论】: