How to get the current application icon in ios

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

    Because it took me a little while to work out, here is a working Swift solution.

    let primaryIconsDictionary = NSBundle.mainBundle().infoDictionary?["CFBundleIcons"]?["CFBundlePrimaryIcon"] as? NSDictionary
    let iconFiles = primaryIconsDictionary!["CFBundleIconFiles"] as NSArray
    let lastIcon = iconFiles.lastObject as NSString //last seems to be largest, use first for smallest
    let theIcon = UIImage(named: lastIcon)
    
    let iconImageView = UIImageView(image: theIcon)
    

提交回复
热议问题