美文网首页
Swift 动态更改桌面图标,有弹窗这个很烦!

Swift 动态更改桌面图标,有弹窗这个很烦!

作者: Matsonga | 来源:发表于2021-04-16 09:46 被阅读0次
目录
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIcons</key>
    <dict>
        <key>CFBundleAlternateIcons</key>
        <dict>
<!--            -->
            <key>desktopIconS</key>
            <dict>
                <key>CFBundleIconFiles</key>
                <array>
                    <string>desktopIconS</string>
                </array>
            </dict>
<!--            -->
            <key>desktopIconK</key>
            <dict>
                <key>CFBundleIconFiles</key>
                <array>
                    <string>desktopIconK</string>
                </array>
            </dict>
<!--        -->
        </dict>
        <key>CFBundlePrimaryIcon</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string></string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
        <key>UINewsstandIcon</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string></string>
            </array>
            <key>UINewsstandBindingEdge</key>
            <string>UINewsstandBindingEdgeLeft</string>
            <key>UINewsstandBindingType</key>
            <string>UINewsstandBindingTypeMagazine</string>
        </dict>
    </dict>
    func changeIcon(to name: String?) {
        // 检查应用程序是否支持更换图标
        guard UIApplication.shared.supportsAlternateIcons else {
            return;
        }
        
        // 将图标更改为指定名称的图片
        UIApplication.shared.setAlternateIconName(name) { (error) in
            // 应用程序图标更改后,打印错误或成功信息
            if let error = error {
                print("由于以下原因,应用程序图标无法显示 \(error.localizedDescription)")
            } else {
                print("应用程序图标已成功更改。")
            }
        }
        
    }

相关文章

网友评论

      本文标题:Swift 动态更改桌面图标,有弹窗这个很烦!

      本文链接:https://www.haomeiwen.com/subject/yugslltx.html