ioscocoa-touchnsbundleuiapplication

How to get the current application icon in ios


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


Solution

  • Works for Swift 4.1 and extending it for Bundle.

    extension Bundle {
        public var icon: UIImage? {
            if let icons = infoDictionary?["CFBundleIcons"] as? [String: Any],
                let primaryIcon = icons["CFBundlePrimaryIcon"] as? [String: Any],
                let iconFiles = primaryIcon["CFBundleIconFiles"] as? [String],
                let lastIcon = iconFiles.last {
                return UIImage(named: lastIcon)
            }
            return nil
        }
    }
    

    To use in an app, call Bundle.main.icon.