- Info.plist
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>原AppIcon图标名</string>
</array>
</dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>icon01</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>AppIcon图标名2</string>
</array>
</dict>
<key>icon02</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>AppIcon图标名3</string>
</array>
</dict>
</dict>
</dict>
-
将所有AppIcon放入工程中(不要放在Assets.xcassets)
-
代码
// 更换
if ([UIApplication sharedApplication].supportsAlternateIcons) {
[[UIApplication sharedApplication] setAlternateIconName:图标名 completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"success:%@",图标名);
}else{
NSLog(@"error:%@",error);
}
}];
} else {
NSLog(@"不能更换icon");
return;
}
}
// 还原
if ([UIApplication sharedApplication].alternateIconName != nil) { // 图标被替换过
// 重置icon
[[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"success");
} else {
NSLog(@"error:%@",error);
}
}];
}
网友评论