代码= 3072“操作被取消".设置备用应用程序图标时 [英] Code=3072 "The operation was cancelled" when setting alternate app icon

查看:119
本文介绍了代码= 3072“操作被取消".设置备用应用程序图标时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个名为备用应用程序图标我的iOS应用中的code> MyIcon .我的项目包中有一个 MyIcon.png 图像(不在我的Assets文件夹中),并且在Info.plist中声明了它,如下所示:

I am trying to set an alternate app icon named MyIcon in my iOS app. I have a MyIcon.png image in my project bundle (not in my Assets folder) and it is declared in my Info.plist like so:

<key>CFBundleIcons</key>
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>MyIcon</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>MyIcon</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
    </dict>
</dict>

在我的代码中,我尝试更改应用程序图标:

In my code, I try to change the app icon:

UIApplication.shared.setAlternateIconName("MyIcon")

但是,图标并没有改变,而是在控制台中给了我这个错误:

However, the icon doesn't change and I am instead given this error in the console:

Error Domain=NSCocoaErrorDomain Code=3072 "The operation was cancelled."

如何解决此问题?

推荐答案

由于两个原因,我收到此错误,

I was getting this error because of two reasons,

  • 首先,我没有通过将png文件添加到项目中来执行将文件添加到'ProjectNameFoo'" .否则它不起作用.之后,它开始显示图标.
  • 其次,出现此错误是因为我试图在 viewDidLoad 中更改图标.我不为什么,但这给了我同样的错误.当我像下面的代码那样延迟尝试时,无论我付出多少秒,它都可以正常工作.

  • First, I didn't do "Add Files to 'ProjectNameFoo'" by adding png file to project. Otherwise it didn't work. After that it started to see icon.
  • Secondly, I was getting this error because I was trying to change icon after in viewDidLoad. I don't why but it was giving me same error. When I try with a delay like the code below it was working whatever second I gave.

override func viewDidLoad() {
    super.viewDidLoad()

    delay(0.01) {
        if foo().isFoo() {
            print("")

            self.changeIcon(name: "ColdRabbit")
        }
        else {
            print("")
        }
    }
}

func delay(_ delay:Double, closure:@escaping ()->()) {
    let when = DispatchTime.now() + delay
    DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}

这篇关于代码= 3072“操作被取消".设置备用应用程序图标时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆