美文网首页
iOS App内更换AppIcon(iOS 10.3及以上系统版

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

作者: 门前有棵葡萄树 | 来源:发表于2019-10-25 15:09 被阅读0次

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);
        }];
    }

相关文章

网友评论

      本文标题:iOS App内更换AppIcon(iOS 10.3及以上系统版

      本文链接:https://www.haomeiwen.com/subject/daisvctx.html