Get icon for another application in Objective-C

前端 未结 3 838
我在风中等你
我在风中等你 2021-02-08 17:00

How do I get the icon from another application using Objective-C?

I have tried this so far, however it just returns null:

NSURL *path = [NSU         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-02-08 17:46

    You can use NSWorkspace, e.g.

    NSImage *image = [[NSWorkspace sharedWorkspace] iconForFile:path];
    

    If you want to use the app bundleId instead of knowing its path, you can do this first

    path = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:bundleIdentifier];
    

提交回复
热议问题