I have followed few tutorials on setting alternative icons in iOS but I cannot get it to work properly. The important part in my Info.plist looks like this:
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>default</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>six</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>six</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>crazy</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>crazy</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
</dict>
</dict>
And the code for the view controller, very simple:
class ViewController: UIViewController {
@IBOutlet weak var segment: UISegmentedControl!
override func viewDidLoad() {
super.viewDidLoad()
segment.addTarget(self, action: #selector(segmentChanged(_:)), for: .valueChanged)
// Do any additional setup after loading the view, typically from a nib.
}
@objc func segmentChanged(_ sender: UISegmentedControl) {
var icon: String?
switch sender.selectedSegmentIndex {
case 1:
icon = "six"
case 2:
icon = "crazy"
default:
icon = nil
}
changeIcon(icon)
}
func changeIcon(_ icon: String?) {
if UIApplication.shared.supportsAlternateIcons {
UIApplication.shared.setAlternateIconName(icon, completionHandler: { (error) in
print("\(error?.localizedDescription)")
})
}
}
}
When the method gets called I get prompt saying
You have changed the icon for "App".
But the icon that is displayed is the default one My icon files are named: six@2x.png, six@3x.png, crazy@2x.png, crazy@3x.png, default@2x.png, default@3x.png Why is it not changing? Are there any special steps for putting the image files in the project? I have put mine in the "res" folder
Project: https://www.dropbox.com/s/nboslz2s6gagvwl/AltIcon.zip?dl=0
Turns out it was problem with the software I was using to scale down images, it wasn't saving PNG files properly.