在Objective-C中获取另一个应用程序的图标 [英] Get icon for another application in Objective-C
本文介绍了在Objective-C中获取另一个应用程序的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Objective-C从另一个应用程序中获取图标?
How do I get the icon from another application using Objective-C?
到目前为止,我已经尝试过了,但是它只返回null
:
I have tried this so far, however it just returns null
:
NSURL *path = [NSURL URLWithString:@"/Applications/Calculator.app"];
NSLog(@"%@", path);
NSImage *image = (__bridge NSImage *)(QLThumbnailImageCreate(kCFAllocatorDefault, (__bridge CFURLRef)(path), CGSizeMake(100, 100), (__bridge CFDictionaryRef)(@{(NSString *)kQLThumbnailOptionIconModeKey: @NO})));
NSLog(@"%@", image);
推荐答案
例如,您可以使用NSWorkspace
You can use NSWorkspace, e.g.
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFile:path];
如果您想使用应用程序bundleId
而不是知道其路径,则可以先执行此操作
If you want to use the app bundleId
instead of knowing its path, you can do this first
path = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:bundleIdentifier];
这篇关于在Objective-C中获取另一个应用程序的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文