Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 640
the Reverend Avatar asked Feb 23 '12 18:02

the Reverend


People also ask

How do I get app icons for iOS?

Type “Open app” in the search bar. Tap “App” to select which icon to replace. Tap “Add to Home Screen.” You'll now see a preview of the icon (which will be a standard, uninteresting icon that Shortcuts automatically adds).

How do you update app icons in iOS?

Tap the placeholder app icon. From the drop-down menu, select Take Photo, Choose Photo, or Choose File, depending on where your replacement app icon image is located. Select your replacement image. In the text field, rename the app as you want it to appear on the home screen.

Why are my app icons not showing iOS?

If you're able to fetch the app through Spotlight Search and App library but can't seem to locate its icon, it's possible that you might have hidden the Home Screen page containing that icon. To unhide your Home Screen, tap and hold anywhere on the empty space on your Home Screen.


2 Answers

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.

like image 91
samwize Avatar answered Sep 22 '22 06:09

samwize


Here is a Swift 4.x && 3.x extension to UIApplication for obtaining the application icon. You can choose whether to get the smallest or largest icon based on the location of the icon path you pull from the iconFiles array.

extension UIApplication {     var icon: UIImage? {         guard let iconsDictionary = Bundle.main.infoDictionary?["CFBundleIcons"] as? NSDictionary,             let primaryIconsDictionary = iconsDictionary["CFBundlePrimaryIcon"] as? NSDictionary,             let iconFiles = primaryIconsDictionary["CFBundleIconFiles"] as? NSArray,             // First will be smallest for the device class, last will be the largest for device class             let lastIcon = iconFiles.lastObject as? String,             let icon = UIImage(named: lastIcon) else {                 return nil         }          return icon     } } 

To access the icon, call the following:

let icon = UIApplication.shared.icon 

For bonus points, you could even make two vars to get the smallest and largest icon if your app needed it.

like image 29
CodeBender Avatar answered Sep 18 '22 06:09

CodeBender