title: iOS - Dynamic app icons for iPhone and iPad devices
body: <p>I am trying to change the app icon dynamically using <code>setAlternateIconName</code> and I faced an issue in the iPhone X device where a blank icon is shown instead of the expected icon. This works fine on iPhone 6s, iPhone 8 and iPhone 13 pro devices (I use an M1 Mac and the project won't work on Simulators). Also I would like the dynamic app icon for the iPad target as well. The requirement is to support an additional app icon to the existing one.</p>
  <p><a href="https://i.stack.imgur.com/9Be9M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Be9M.png" alt="enter image description here" /></a></p>
  <p>The above icon images are added to the project bundle for the new icon.</p>
  <p>The code for my app icon manager is as follows:</p>
  <pre><code>enum ONAppIcon: CaseIterable {
  case normal,
  hematology
  
  var name: String? {
      switch self {
      case .normal:
          return nil
      case .hematology:
          return &quot;icon-hem&quot;
      }
  }
  
      var preview: UIImage {
          switch self {
          case .normal:
              return #imageLiteral(resourceName: &quot;icon-onc@2x.png&quot;)
          case .hematology:
              if UIDevice.current.userInterfaceIdiom == .pad {
                  return #imageLiteral(resourceName: &quot;icon-hem-ipad@2x.png&quot;)
              }
              return #imageLiteral(resourceName: &quot;icon-hem@2x.png&quot;)
          }
      }
  }
  
  class AppIconManager {
      static let shared = AppIconManager()
      var current: ONAppIcon {
          if #available(iOS 10.3, *) {
              return ONAppIcon.allCases.first(where: {
                $0.name == UIApplication.shared.alternateIconName
              }) ?? .normal
          }
          return .normal
      }
  
      func setIcon(_ appIcon: ONAppIcon, completion: ((Bool) -&gt; Void)? = nil) {
    
          if #available(iOS 10.3, *) {
              guard current != appIcon,
                UIApplication.shared.supportsAlternateIcons
              else { return }
              UIApplication.shared.setAlternateIconName(appIcon.name) { error in
                if let error = error {
                  print(&quot;Error setting alternate icon \(appIcon.name ?? &quot;&quot;): \(error.localizedDescription)&quot;)
                }
                completion?(error != nil)
              }
          }
      }
  }
  </code></pre>
  <p>The Info.plist contents are as follows:
  <a href="https://i.stack.imgur.com/fTwcP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fTwcP.png" alt="enter image description here" /></a></p>
  <ol>
  <li>What are the app icon sizes to be added to support dynamic app icons for both iPhone and iPad devices?</li>
  <li>Is there any naming convention for the images?</li>
  <li>How to add the icon files correctly in the Info.plist file?</li>
  </ol>