Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing alternate icon for iPad

Tags:

I have a problem with changing app's icon on iPad. Everything is working fine on iPhone but on iPad I get this error :

[default] Failed to set preferredIconName to AI-Gorgosaurus for ...:0> error: Error Domain=NSCocoaErrorDomain Code=4 "The file doesn’t exist." UserInfo={NSUnderlyingError=0x600000248a30 {Error Domain=LSApplicationWorkspaceErrorDomain Code=-105 "iconName not found in CFBundleAlternateIcons entry" UserInfo={NSLocalizedDescription=iconName not found in CFBundleAlternateIcons entry}}} App icon failed to due to The file doesn’t exist.

I searched ad found that I need to add ~ipad in CFBundleIconFiles but still get the same error!.

Here is the code:

  func changeIcon(to name: String?) {         //Check if the app supports alternating icons         guard UIApplication.shared.supportsAlternateIcons else {             return;         }          //Change the icon to a specific image with given name         UIApplication.shared.setAlternateIconName(name) { (error) in             //After app icon changed, print our error or success message             if let error = error {                 print("App icon failed to due to \(error.localizedDescription)")             } else {                 print("App icon changed successfully.")             }         }     } 

enter image description here

I just tested on another project and works fine !!! but not on my current project why ?! have you any idea?

like image 703
iOS.Lover Avatar asked Aug 21 '18 13:08

iOS.Lover


People also ask

How do I change the home screen icon on my iPad?

Touch and hold any app or widget on the Home Screen, then tap Edit Home Screen. The items begin to jiggle. Drag the app to the right edge of the screen. You might need to wait a second for the new page to appear.

How do I manually change an icon?

Right-click the icon and click Properties. Click the Shortcut tab (if one is available), and then click Change Icon. Click the icon that you want to use from the list, click OK, and then click OK.

How do I change one second everyday icon?

To find it, scroll up until you see Today and keep scrolling up in a Journal project until the icons' screen shows up. From there, you can select any icon that's available to you. The more snippets you add, the more icons you'll unlock!


2 Answers

Your info.plist is structured incorrectly.

You have:

- CFBundleIcons   - CFBundleAlternateIcons     - Icon Name       - CFBundleIconFiles       - CFBundleIconFiles~ipad 

But it should be:

- CFBundleIcons   - CFBundleAlternateIcons     - Icon Name       - CFBundleIconFiles - CFBundleIcons~ipad   - CFBundleAlternateIcons     - Icon Name      - CFBundleIconFiles 

Basically, once you have it working with iPhone icons, CFBundleIcons, duplicate the entire tree as CFBundleIcons~ipad. The iPad files shouldn't be nested under CFBundleIcons at all.

You're mixing up CFBundleIcons~ipad and CFBundleIconFiles~ipad (which isn't a valid key).

Screenshot

like image 176
Dave Wood Avatar answered Sep 28 '22 03:09

Dave Wood


Attempting to give a more re-useable (easy to copy/paste) version of this answer.

1) You need images of the following names and sizes added as regular .png files (no asset catalogues)

.../AppIcon-Dark/iPad-app.png   pixelWidth: 76 .../AppIcon-Dark/[email protected]   pixelWidth: 152 .../AppIcon-Dark/[email protected]   pixelWidth: 167 .../AppIcon-Dark/[email protected]   pixelWidth: 120 .../AppIcon-Dark/[email protected]   pixelWidth: 180 

you can then add/insert the following in your info.plist

<key>CFBundleIcons</key> <dict>     <key>CFBundleAlternateIcons</key>     <dict>         <key>AppIcon-Dark</key>         <dict>             <key>CFBundleIconFiles</key>             <array>                 <string>iPhone-app</string>             </array>         </dict>     </dict>     <key>CFBundlePrimaryIcon</key>     <dict>         <key>CFBundleIconFiles</key>         <array>             <string>AppIcon</string>         </array>     </dict> </dict> <key>CFBundleIcons~ipad</key> <dict>     <key>CFBundleAlternateIcons</key>     <dict>         <key>AppIcon-Dark</key>         <dict>             <key>CFBundleIconFiles</key>             <array>                 <string>iPad-app</string>                 <string>iPad-pro</string>             </array>         </dict>     </dict>     <key>CFBundlePrimaryIcon</key>     <dict>         <key>CFBundleIconFiles</key>         <array>             <string>AppIcon</string>         </array>     </dict> </dict> 

I then set my icon with the following

func updateIcon() {     if #available(iOS 13.0, *) {         let dark = window?.traitCollection.userInterfaceStyle == .dark          let currentIconName = UIApplication.shared.alternateIconName         let desiredIconName:String? = dark ? "AppIcon-Dark" : nil          if currentIconName != desiredIconName {             UIApplication.shared.setAlternateIconName(desiredIconName) {                 (error) in                 print("failed: \(String(describing: error))")             }         }     } } 
like image 43
Confused Vorlon Avatar answered Sep 28 '22 05:09

Confused Vorlon