前提:仅支持iOS13之后的版本
节假日、特殊活动等可根据后端配置接口获取的数据灵活更换
首先准备好需要更换的图片,手机尺寸:20、29、40、60,ipad尺寸:29、40、60、76、83.5
在info.plist中添加对应项
应用启动后调用约定好的接口,接口返回当前想要加载的是哪个icon
请求成功后调用以下方法进行设置
#pragma mark- 设置icon
- (void)setIconName:(NSString*)iconName{
if(@available(iOS10.3, *)) {
if ([[UIApplication sharedApplication] respondsToSelector:@selector(supportsAlternateIcons)] && [[UIApplication sharedApplication] supportsAlternateIcons]){
NSMutableString *selectorString = [[NSMutableString alloc] initWithCapacity:40];
[selectorStringappendString:@"_setAlternate"];
[selectorStringappendString:@"IconName:"];
[selectorStringappendString:@"completionHandler:"];
SELselector =NSSelectorFromString(selectorString);
IMP imp = [[UIApplication sharedApplication] methodForSelector:selector];
void(*func)(id,SEL,id,id) = (void*)imp;
if(func){
func([UIApplicationsharedApplication], selector, iconName, ^(NSError*_Nullableerror) {});
}
}
}else{
// Fallback on earlier versions
}
}