【问题标题】:Is it possible to change the app icon while the App is running是否可以在应用程序运行时更改应用程序图标
【发布时间】:2021-09-07 15:42:35
【问题描述】:

不是一个真正重要的问题,只是好奇。你可以在运行时更改应用程序图标吗?例如,有一个按钮,当你按下按钮时,你会得到一个不同的应用程序图标(假设应用程序图标已经“设置”)。 Android 和 iOS。

非常感谢任何输入。 谢谢

【问题讨论】:

    标签: android ios flutter dart appicon


    【解决方案1】:

    自 iOS 10.3 起,开发者可以通过编程方式更改应用图标。

    详情可以参考这个link,它展示了如何动态改变应用图标。

    示例代码:

    // change app icon to "Picture A"
    @IBAction func pichuButtonDidTap(_ sender: UIButton) {
      changeIcon(to: "Picture A")
    }
    
    // change app icon to "Picture B"
    @IBAction func pikachuButtonDidTap(_ sender: UIButton) {
      changeIcon(to: "Picture B")
    }
    
    // change app icon to "Picture C"
    @IBAction func raichuButtonDidTap(_ sender: UIButton) {
      changeIcon(to: "Picture C")
    }
    func changeIcon(to iconName: String) {
      // 1
      guard UIApplication.shared.supportsAlternateIcons else {
        return
      }
    
      // 2
      UIApplication.shared.setAlternateIconName(iconName, completionHandler: { (error) in
        // 3
        if let error = error {
          print("App icon failed to change due to \(error.localizedDescription)")
        } else {
          print("App icon changed successfully")
        }
      })
    }
    

    【讨论】:

      【解决方案2】:

      您不能更改已签名并密封的 APK 中的清单或资源,除非通过软件升级。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-22
        • 2023-03-17
        • 1970-01-01
        • 1970-01-01
        • 2012-02-22
        • 1970-01-01
        相关资源
        最近更新 更多