功能
切换APP图标是iOS10.3的新特性,用户可以根据需要选择不同的APP图标。注意:目前只能提前将图标加入到APP并做相应配置,暂时不支持从网络下载新的图标。
CFBundleIcons
实现切换APP图标功能,需要在info.plist文件配置CFBundleIcons,用于指定APP图标的信息,包含三种类型的key:1.CFBundlePrimaryIcon 这个key指定默认的APP图标,包含两个key:
CFBundleIconFiles:默认图标名字
UIPrerenderedIcon:指定该图标是否已经包含闪耀的效果,一般为NO
示例:
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>天气</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
2.CFBundleAlternateIcons这个key指定可以替换的APP图标,包含两个key
CFBundleIconFiles:替换图标名字
UIPrerenderedIcon:指定该图标是否已经包含闪耀的效果,一般为NO
<key>CFBundleAlternateIcons</key>
<dict>
<key>rain</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>rain</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>snow</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>snow</string>
</array>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
</dict>
注意:在指定图标名字时,最好忽略图标文件的扩展名,系统会自动选择最佳版本的图标文件。如果要指定图标文件扩展名,则所有图标都有指定文件扩展
API介绍
在实现APP图标切换主要使用以下3个属性或方法:1.
@property(readonly, nonatomic) BOOLsupportsAlternateIcons;
说明:当属性值为YES时,系统才支持切换APP图标。
2.
- (void)setAlternateIconName:(NSString *)alternateIconName completionHandler:(void (^)(NSError *error))completionHandler;
说明:
alternateIconName 表示切换图标的名字,如果其值为nil,将展示APP的primary图标completionHandler 切换后调用,不必须在主线程执行
3.
@property(readonly, nonatomic) NSString *alternateIconName;
说明:正在显示的图标的名字
实现
1.导入APP图标2.配置CFBundleIcons
3.切换APP图标