时常看到一些app在未更新的情况下,就实现了AppIcon的切换,常见的比如说淘宝、ZFB。我不大确定是否他们是在版本未更新且未启动app的情况就实现了AppIcon的切换,如果有人知道可以给我留言,大家再探讨一下。
下面我们主要探讨的是如何在app启动的情况下切换AppIcon
@interface UIApplication (UIAlternateApplicationIcons)
// If false, alternate icons are not supported for the current process.
@property (readonly, nonatomic) BOOL supportsAlternateIcons NS_EXTENSION_UNAVAILABLE("Extensions may not have alternate icons") API_AVAILABLE(ios(10.3), tvos(10.2));
// Pass `nil` to use the primary application icon. The completion handler will be invoked asynchronously on an arbitrary background queue; be sure to dispatch back to the main queue before doing any further UI work.
- (void)setAlternateIconName:(nullable NSString *)alternateIconName completionHandler:(nullable void (^)(NSError *_Nullable error))completionHandler NS_EXTENSION_UNAVAILABLE("Extensions may not have alternate icons") API_AVAILABLE(ios(10.3), tvos(10.2));
// If `nil`, the primary application icon is being used.
@property (nullable, readonly, nonatomic) NSString *alternateIconName NS_EXTENSION_UNAVAILABLE("Extensions may not have alternate icons") API_AVAILABLE(ios(10.3), tvos(10.2));
@end
supportsAlternateIcons 主要是判断当前是否能够进行切换APPicon,
alternateIconName 可以获取当前显示的APPicon,如果获取到位nil,则当前的APPicon为初始的icon
-(void)setAlternateIconName:(nullable NSString *)alternateIconName completionHandler:(nullable void (^)(NSError *_Nullable error))completionHandler
则是通过指定的alternateIconName来设置切换APPicon
那么什么是alternateIconName?
通过shift+com+0,我们可以对api进一步的深入了解。实际上需要我们在plist中进行设置CFBundleAlternateIcons的key
具体的实现各位看官老爷可以点击前往这里
到这里为止基本就结束了,可以看到实际上达到修改APPicon的功能,我们必须保证这样2个前提:
- plist中预先存在了对应的alternateIconName
- app启动状态下执行修改APPicon的代码
那么接下来我们来动态修改plist文件
好吧最后发现貌似不能修改plist...
那么试试在app未启动状态下如何修改APPicon的代码