How to get the current application icon in ios

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

    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.

提交回复
热议问题