我遵循了一些关于在 iOS 中设置替代图标的教程,但我无法让它正常工作。我的 Info.plist 中的重要部分如下所示:
<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>
还有 View Controller 的代码,很简单:
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)")
})
}
}
}
当方法被调用时,我会提示说
You have changed the icon for "App".
但是显示的图标是默认的
我的图标文件命名为:[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
为什么它没有改变?将图像文件放入项目中是否有任何特殊步骤?我已经把我的放在“res”文件夹中了
项目:
https://www.dropbox.com/s/nboslz2s6gagvwl/AltIcon.zip?dl=0
Best Answer-推荐答案 strong>
原来是我用来缩小图像的软件有问题,它没有正确保存 PNG 文件。
关于iOS备用图标没有改变,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/48381269/
|