iOS动态修改app图标

在iOS10.3以后
UIApplication多了个分类UIAlternateApplicationIcons

@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

1.supportsAlternateIcons设置为YES
2.动态修改的icon不能放在Assets.xcassets里
新建个文件夹放
3.info.plist里面添加
4.切换代码

    [[UIApplication sharedApplication] setAlternateIconName:@"snow" completionHandler:^(NSError * _Nullable error) {
        if(error){
            NSLog(@"更换失败");
        }
    }];

详细的不想写了,见原文

https://www.jianshu.com/p/69313970d0e7

你可能感兴趣的:(iOS动态修改app图标)