How to get the current application icon in ios

后端 未结 9 2099
心在旅途
心在旅途 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:32

    This is how the icons is set inside the info.plist,

    //try doing NSLog(@"%@",[[NSBundle mainBundle] infoDictionary]);
    
     CFBundleIcons =     {
            CFBundlePrimaryIcon =         {
                CFBundleIconFiles =             (
                    "icon.png",//App icon added by you
                    "icon@2x.png"//App icon in retina added by you
                );
                UIPrerenderedIcon = 1;
            };
        };
    

    If you want to get the app icon use below code:

    UIImage *appIcon = [UIImage imageNamed: [[[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIcons"] objectForKey:@"CFBundlePrimaryIcon"] objectForKey:@"CFBundleIconFiles"] objectAtIndex:0]];
    

    P.S: UIImage automatically picks the suitable icon for retina display.

    I hope it helps!!

提交回复
热议问题