Installing an alternate application icon returns error 3072: “Operation was canceled” in iOS 10.3

I try to set alternative icons for my application in iOS 10.3 , but every time I call the Xcode method, it returns:

Domain Error = NSCocoaErrorDomain Code = 3072 "Operation was canceled."

I use @KlimczakM's answer from this to set the icon ( specifyIcon method below), but I use my own method to load the preferred icon from the 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 answer) } 

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> 

All these icons are contained as PNG files in the "resources" folder inside my application package.

How can I fix this problem?

+6
source share
1 answer

I got this error for two reasons:

  • Firstly, I didn’t do “Add files to ProjectNameFoo” by adding a png file to the project. Otherwise, it didn’t work. After that, he started to see the icon.
  • Secondly, I was getting this error because I was trying to change the icon after in viewDidLoad. I do not understand, but it gave me the same error. When I try with a delay, like the code below, it worked no matter what 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) } 
+4
source

Source: https://habr.com/ru/post/1014927/


All Articles