1 准备图标
准备2个种图标,一个默认的图标(imagecontrolIcon),一个即将要改的图标(beaconIcon),并且放在项目中如图
【图标名字自己定义,注意图标命名格式】
2 修改info.plist
如图所示
源码显示info.plist,文件右键,open as -> source code
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>imagecontrolIcon</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>beaconIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>beaconIcon</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
</dict>
</dict>
3 代码实现
仅限于iOS版本10.3以上
if #available(iOS 10.3, *) {
UIApplication.shared.setAlternateIconName("beaconIcon", completionHandler: { (Error) in
if(Error != nil){
print("error:" + Error.debugDescription);
}
else{
print("ok");
}
})
}
else{
print("版本低");
}
4 问题总结
1 按照以上步骤做,如果提示文件不存在,则检查资源文件中的Applcon是否有图片
如果有图片请全部清空,否则会一直提示这个错误,这个问题搞了1个小时,心累啊。
error:Optional(Error Domain=NSCocoaErrorDomain Code=4 "该文件不存在。" UserInfo={NSUnderlyingError=0x600000259a10 {Error Domain=LSApplicationWorkspaceErrorDomain Code=-105 "iconName not found in CFBundleAlternateIcons entry" UserInfo={NSLocalizedDescription=iconName not found in CFBundleAlternateIcons entry}}})
2 当打包上传时又出现问题ITMS-90023,出现以下错误,我的app用在ipad上,需要图片76x76,和152x152像素的图片,解决方法是向项目里添加2张图片,只要像素是76x76,152x152即可,图片名称没有要求,自定义即可,如下图所示
3 问题2的后续问题
按照问题2可以成功上传到app store,但是它又给我发邮件说还是缺少图片,也就是说问题2还是没解决,进入itunes里看,还是没有构建的版本,也就是说问题2没有解决,正在解决中,请稍后,如果有新的方法求告知,我现在在info.plist里添加文件说明试试,正在实践中..............
下面是图标格式
https://developer.apple.com/library/content/qa/qa1686/_index.html
Image Size (px) | File Name | Used For | App Store | Ad Hoc |
---|---|---|---|---|
512x512 | iTunesArtwork | Ad Hoc iTunes | Do not include | Optional but recommended |
1024x1024 | [email protected] | Ad Hoc iTunes on devices with retina display | Do not include | Optional but recommended |
76x76 | Icon-76.png | Home screen on iPad | Required | Required |
152x152 | [email protected] | Home screen on iPad with retina display | Optional but recommended | Optional but recommended |
167x167 | [email protected] | Home screen on iPad Pro | Optional but recommended | Optional but recommended |
40x40 | Icon-Small-40.png | Spotlight | Optional but recommended | Optional but recommended |
80x80 | [email protected] | Spotlight on devices with retina display | Optional but recommended | Optional but recommended |
29x29 | Icon-Small.png | Settings | Recommended if you have a Settings bundle, otherwise optional but recommended | Recommended if you have a Settings bundle, otherwise optional but recommended |
58x58 | [email protected] | Settings on devices with retina display | Recommended if you have a Settings bundle, otherwise optional but recommended | Recommended if you have a Settings bundle, otherwise optional but recommended |
那就按照他的图标来做修改,按照格式命名,到此处已经完成上传,等待验证