iOS 10.3 - How to change app icon programmatically [duplicate]

心不动则不痛 提交于 2019-12-04 04:18:57

Yes, iOS 10.3 finally gives developers the ability to change their app’s icon programmatically.

It is possible to change appIcon from iOS 10.3. For that you need to set supportsAlternateIcon to Yes in info.plist.

Both primary and secondary icons should be added in CFBundleIcons key of your app's Info.plist file.

//Info.plist
<key>CFBundleIcons</key>
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>Icon1</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>alternater1</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
        <key>Icon2</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>alternater2</string>
            </array>
        </dict>
    </dict>
</dict>

To change App Icon following UIApplication method needs to be called:

Objective C:

[[UIApplication sharedApplication] setAlternateIconName:@"alternater2" completionHandler:^(NSError * _Nullable error) {
        NSLog(@"Error...");
}];

Swift 3:

if UIApplication.shared.supportsAlternateIcons{
        UIApplication.shared.setAlternateIconName("alternater2", completionHandler: { (error) in
            print(error ?? "")
        })
}

For more detailed tutorial, See:
Apple Document: setAlternateIconName(_:completionHandler:)
How to change your app icon dynamically with setAlternateIconName()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!