开发者

How to access QuickLook plugin resources?

My QuickLook plugin generates HMTL preview for the docum开发者_JAVA技巧ent. I need to display images saved in the plugin bundle. Simply using imageNamed: method to get an instance of the NSImage class doesn't work. How can achieve that? Is that a consequence of the fact that

Quick Look generators are designed as CFPlugIn-style bundles.

as the documentation says?


I believe +imageNamed: uses the +mainBundle method of NSBundle. In that case, that's not your plugin's bundle.

I think you'll need to ask the plugin's bundle directly:

NSString * path = [[[NSBundle bundleForClass:[MyPluginClass class]] pathForResource:@"MyImage" ofType:@"tif"];
NSImage * image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];

This was written in the browser, so it may not be exact. :-)


Within the plug-in code, you can access your plug-in CFBundle:

QLThumbnailRequestGetGeneratorBundle or QLPreviewRequestGetGeneratorBundle

Once you have the bundle, you can query for resources file URLs using:

CFBundleCopyResourceURL

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜