QuickLook plugin fails to display HTML

467 views Asked by At

I'm attempting to display HTML in a QuickLook plugin.

GeneratePreviewForURL method:

...

NSMutableString *html=[[NSMutableString alloc] init];

[html appendString:@"<html>"];
[html appendString:@"<body>"];
[html appendString:@"<h1>First Last</h1>"];
[html appendString:@"</body>"];
[html appendString:@"</html>"];

QLPreviewRequestSetDataRepresentation(
  preview,
  (__bridge CFDataRef)[html dataUsingEncoding:NSUTF8StringEncoding],
  kUTTypePlainText,
  NULL
);

...

The preview window displays the HTML as plain text:

<html><body><h1>First Last</h1></body></html>

However, when I switch to HTML:

...

NSDictionary *properties = @{
  (__bridge NSString *)kQLPreviewPropertyTextEncodingNameKey : @"UTF-8",
  (__bridge NSString *)kQLPreviewPropertyMIMETypeKey : @"text/html"
};

QLPreviewRequestSetDataRepresentation(
  preview,
  (__bridge CFDataRef)[html dataUsingEncoding:NSUTF8StringEncoding],
  kUTTypeHTML,
  (__bridge CFDictionaryRef)properties
);

...

** edit **

The preview window isn't displayed in debugging mode, however, selecting a contact (from Spotlight, for example) will display the preview.

** / edit **

Eventually, I get warnings (listed below).

What am I missing? Why does the preview work differently than the compiled code?

Trace:

Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const: conn 0x32807 token 0x1ffffffffffe85
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: Backtrace (at 118686):
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  0   CoreGraphics                        0x00007fff913f9215 CGSBacktraceCreate + 59
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  1   CoreGraphics                        0x00007fff91418688 _ZN16CGSUpdateManager14disable_updateEv + 84
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  2   AppKit                              0x00007fff8738ede5 -[NSWindow disableScreenUpdatesUntilFlush] + 127
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  3   AppKit                              0x00007fff878c394d -[NSVisualEffectView _createOrUpdateBackdrop:view:vibrancyEffect:] + 823
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  4   AppKit                              0x00007fff878c466a -[NSVisualEffectView _updateCGSWindowBackdrop] + 70
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  5   AppKit                              0x00007fff878c8294 -[NSVisualEffectView _update] + 147
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  6   AppKit                              0x00007fff878c7fc1 -[NSVisualEffectView layout] + 59
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  7   AppKit                              0x00007fff87370f54 -[NSView _layoutSubtreeWithOldSize:] + 373
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  8   AppKit                              0x00007fff873711a5 -[NSView _layoutSubtreeWithOldSize:] + 966
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  9   AppKit                              0x00007fff87364970 -[NSView layoutSubtreeIfNeeded] + 885
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  10  AppKit                              0x00007fff879e0e7a _NSViewLayoutSubtreesThatUseAutolayoutIfNeeded + 71
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  11  AppKit                              0x00007fff873c5b0f -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 82
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  12  AppKit                              0x00007fff873f5569 -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 244
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  13  AppKit                              0x00007fff8743162e _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 612
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  14  AppKit                              0x00007fff879f6cf1 __83-[NSWindow _postWindowNeedsDisplayOrLayoutOrUpdateConstraintsUnlessPostingDisabled]_block_invoke1523 + 46
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  15  CoreFoundation                      0x00007fff923acd87 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  16  CoreFoundation                      0x00007fff923acce0 __CFRunLoopDoObservers + 368
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  17  CoreFoundation                      0x00007fff9239ede8 __CFRunLoopRun + 872
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  18  CoreFoundation                      0x00007fff9239e838 CFRunLoopRunSpecific + 296
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  19  QuickLookUI                         0x00007fff84d2b50b -[QLPreviewView _startTimeOut] + 189
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  20  QuickLookUI                         0x00007fff84d0e1e1 -[QLPreviewPanelController _setCurrentPreviewItem:withTransition:blocking:] + 289
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  21  QuickLookUI                         0x00007fff84d0d916 -[QLPreviewPanelController _refreshLayoutAndContentBlocking:] + 250
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  22  QuickLookUI                         0x00007fff84d0efbc -[QLPreviewPanelController willOpen] + 734
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  23  QuickLookUI                         0x00007fff84d0612c -[QLPreviewPanel _openWithEffect:willOpen:toFullscreen:] + 945
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  24  qlmanage                            0x00000001000253b2 qlmanage + 152498
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  25  qlmanage                            0x0000000100004a8f qlmanage + 19087
Nov 22 07:16:01 Pippin.local qlmanage[46393] <Warning>: void CGSUpdateManager::log() const:  26  libdyld.dylib                       0x00007fff8d7ad5c9 start + 1
3

There are 3 answers

0
Byzantino On

I have the same problem that neither debugging nor running the debug build in Finder would work. However, I observed that if I built the plugin "For Running" then it works just fine in Finder.

0
Anubis On

I have the same exact issue with 'kUTTypeHTML' content type UTI. I cannot debug with Xcode but the deployed plugin works normally in Finder. I think it started happening on Mavericks and later, was able to debug just fine on older versions of OS X and Xcode.

0
Erik Martino On

kUTTypeHTML previews are fixed in Yosemite 10.10.3