iOS App内更换AppIcon(iOS 10.3及以上系统版本)

iOS10.3更换App图标
GitHub地址

效果:

Jietu20191025-150526.gif

步骤:

1.确保Assets.xcassets内无任何图片
15719850866178.jpg
2.将图标拖入项目中,不能使用Assets.xcassets,只能拖入项目。图片大小为60的2倍和3倍,即@2x 120*120``@3x 180*180
15719852465125.jpg
3.配置info.plist,很容易出错,一定要仔细,怕出错可以复制下面的内容,然后替换下图片名称。
15719858457694.jpg
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>app_icon_0</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>app_icon_0</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
        <key>app_icon_1</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>app_icon_1</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
        <key>app_icon_2</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>app_icon_2</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
        <key>app_icon_3</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>app_icon_3</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
    </dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string>app_icon_0</string>
        </array>
        <key>UIPrerenderedIcon</key>
        <false/>
    </dict>
    <key>UINewsstandIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string>app_icon_0</string>
        </array>
        <key>UINewsstandBindingEdge</key>
        <string>UINewsstandBindingEdgeLeft</string>
        <key>UINewsstandBindingType</key>
        <string>UINewsstandBindingTypeMagazine</string>
    </dict>
</dict>
</plist>
4.代码获取当前图标、更换图标

获取当前图标文件名

if (@available(iOS 10.3, *)) {
        NSString *iconName = [UIApplication sharedApplication].alternateIconName;
    }

更换图标

if (@available(iOS 10.3, *)) {
        if (![[UIApplication sharedApplication] supportsAlternateIcons]) {
            return;
        }
        NSArray *weathers = @[@"app_icon_0", @"app_icon_1", @"app_icon_2", @"app_icon_3"];
        NSString *iconName = weathers[sender.selectedSegmentIndex];
        [[UIApplication sharedApplication] setAlternateIconName:iconName completionHandler:^(NSError * _Nullable error) {
            if (!error) {
                return;
            }
            NSLog(@"更换app图标发生错误了 : %@",error);
        }];
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。