设置备用应用程序图标将返回错误3072:“操作已取消”在iOS 10.3中 [英] Setting Alternate App Icon returns error 3072: "The operation was cancelled" in iOS 10.3
问题描述
我正在尝试在 iOS 10.3
中为我的应用设置备用图标,但每次调用方法时Xcode都会返回:
I am trying to set the alternate icons for my app in iOS 10.3
, but every time I call the method Xcode returns:
错误域= NSCocoaErrorDomain代码= 3072操作已取消。
Error Domain=NSCocoaErrorDomain Code=3072 "The operation was cancelled."
我正在使用 @KlimczakM 的答案这个帖子设置图标(下面调用的 specifyIcon
方法),但我使用自己的方法从设置加载首选图标:
I am using @KlimczakM's answer from this post to set the icon (the specifyIcon
method called below) but I am using my own method to load the preferred icon from settings:
let iconSetting = userDefaults.string(forKey: "appIconSetting")
print("The icon setting is: \(iconSetting ?? "error getting appIconSetting.")")
switch iconSetting! {
case "white":
specifyIcon(nil)
case "dark":
specifyIcon("dark")
case "text":
specifyIcon("text")
case "textdark":
specifyIcon("textdark")
case "rainbow":
specifyIcon("rainbow")
default:
specifyIcon(nil)
print("ERROR setting icon.")
}
func specifyIcon(_ icon: String?) {
//(@KlimczakM's answer)
}
在我的 Info.plist中
我有五个图标; 白色
,深色
, rainbow
, text
, textdark
:
In my Info.plist
I have five icons; white
, dark
, rainbow
, text
, and textdark
:
<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>white</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>ic_white</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>dark</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>ic_dark</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>rainbow</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>rainbow</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>text</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>ic_text</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>textdark</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>ic_textdark</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
</dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>ic_white</string>
</array>
</dict>
</dict>
所有这些图标都包含在我的应用包内名为resources的文件夹中的PNG文件中。
All of these icons are contained as PNG files in a folder called "resources" inside my app bundle.
我该如何解决这个问题?
How can I fix this issue?
推荐答案
我得到了这个错误有两个原因,
I was getting this error because of two reasons,
- 首先,我没有做将文件添加到'ProjectNameFoo'通过将png文件添加到项目中。否则它不起作用。之后它开始看到图标。
-
其次,我收到此错误是因为我在 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:“操作已取消”在iOS 10.3中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!