此方法只适用于iOS10.3
// 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));
在info.plist中添加下面信息
###主要实现代码CFBundleIcons 复制代码 CFBundleAlternateIcons star CFBundleIconFiles star-29 star-20 star-40 star-60 UIPrerenderedIcon
-(void)setIcon:(NSString *)iconName{//默认的icon,iconName =nil; NSString *appiconName = [[UIApplication sharedApplication] alternateIconName]; NSLog(@"目前iconName %@",appiconName); [[UIApplication sharedApplication]setAlternateIconName:iconName completionHandler:^(NSError * error){ NSLog(@"samli error %@",error); }];}复制代码
END