How to get the current application icon in ios

后端 未结 9 2106
心在旅途
心在旅途 2020-12-09 03:05

Is there a way to get the current application icon in a cocoa-touch app? Thank you.

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 03:23

    If you use asset catalogues, then you can simply use:

    UIImage* appIcon = [UIImage imageNamed:@"AppIcon60x60"];

    Asset catalogues seem to standardize filenames for app icons.

    Certainly if you need to list all app icons in your bundle you can look it up in CFBundleIconFiles branch of info dictionary.

    Using KVC you can easily get that in a single line of code:

    NSArray* allIcons = [[[NSBundle mainBundle] infoDictionary] valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"];
    

    Resulting array will contain all app icon names available in your bundle. Any of these names can be used to retrieve icon using +[UIImage imageNamed:]

    <__NSCFArray 0x15d54260>(
        AppIcon29x29,
        AppIcon40x40,
        AppIcon60x60
    )
    

提交回复
热议问题