IOS 10.3 - How to programmatically change an application icon

iOS 10.3 comes with an application icon dynamic change feature. Now developers can change application icons without updating the application.

I want to change my application icon dynamically, how can I programmatically change the application icon.

Thanks in advance.

+4
source share
1 answer

Yes, iOS 10.3 finally gives developers the ability to programmatically change the icon of their applications.

You can change the appIcon from iOS 10.3. To do this, you need to set supportsAlternateIconin Yesin info.plist.

Both primary and secondary icons must be added CFBundleIconsto your application info.plist.

//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>

, UIApplication :

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 ?? "")
        })
}

.
Apple Document: setAlternateIconName (_: completeHandler:)
setAlternateIconName()

+7

Source: https://habr.com/ru/post/1674101/


All Articles