Get icon for another application in Objective-C

前端 未结 3 835
我在风中等你
我在风中等你 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

    The icon file of an application is usually defined in its Info.plist under the CFBundleIconFile key. By obtaining the icon file name, you can then get this icon from the Resources directory of a bundle (path-to-anApplication/Contents/Resources/).

    To get the Info.plist contents, you can either load it directly in an NSDictionary (using dictionaryWithContentsOfFile:) or get it from the bundle object of the application (example : [[NSBundle bundleWithPath:path-to-anApp] infoDictionary]).

    The icon file will be the value of the CFBundleIconFile key (i.e.: iconFile = [infoDictionary valueForKey:@"CFBundleIconFile"]. Its path will then be : path-to-anApplication/Contents/Resources/iconFile).

提交回复
热议问题