This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together.

1. Introduction

Before Xcode13 and iOS15 were released, Apple actually supported in-app ICON switching by typing different ICONS into packages, manually configuring them, and then modifying the ICONS through business code. At that time, the application scenario mainly provided users with the initiative to switch different ICONS to their favorite icon style.

After iOS15, apple will support the AppStore package icon switch, the purpose is to determine the user conversion according to different ICONS. Therefore, after Xcode13, the setting method of multi-icon is changed from manual configuration to more convenient configuration.

Because the article was sorted out before iOS15, the new scheme will certainly be more widely used and more convenient for developers to operate. Therefore, I will introduce the two solutions below, but recommend that developers use the latest solution.

2. In the old scheme, manually add the info.plist field

This solution is the old solution before iOS15, suitable for "do not need to switch ICONS through the App Store" scenario, Xcode13 versions can be used in this way.

1.Info.plist Add the following configuration:

<key>CFBundleIcons</key> <dict> <key>CFBundleAlternateIcons</key> <dict> <key>DemoIcon</key> <dict> <key>CFBundleIconFiles</key> <array> <string>DemoIcon-20</string> <string>DemoIcon-29</string> <string>DemoIcon-40</string> <string>DemoIcon-60</string> </array> <key>UIPrerenderedIcon</key> <false/> </dict> </dict>  </dict> <key>CFBundleIcons~ipad</key> <dict> <key>CFBundleAlternateIcons</key> <dict> <key>DemoIcon</key> <dict> <key>CFBundleIconFiles</key> <array> <string>DemoIcon-29</string> <string>DemoIcon-40</string> < string > DemoIcon - 60 < / string > < string > DemoIcon - 76 < / string > < string > DemoIcon 83.5 < / string > < / array > <key>UIPrerenderedIcon</key> <false/> </dict> </dict> </dict>Copy the code
  • If you want to configure multiple sets of ICONS, you need to add images with different names and the same size, and then add a new set of data in CFBundleAlternateIcons of info.plist.
  • Info.plist adds iPad and iPhone configurations. If you only need to adapt iPhone/iPad, you only need to configure iPhone/iPad.

2. Add pictures of the corresponding size to the project (after adding pictures, they should be in the root directory of app after packaging) :

The added image should be the same as the default ICON, no transparent bottom (rounded corner), no alpha channel.

3. (in-code test) Test replacement ICON function:

[[UIApplication sharedApplication] setAlternateIconName:@"DemoIcon" completionHandler:^(NSError * _Nullable error) {
    if (error ! = nil) {
        NSLog(@"set alternative icon error:%@", error.localizedDescription); }}];Copy the code

If a message is displayed indicating that the replacement is successful, the replacement is successful. Otherwise, an error is reported.

If you need to restore the ICON to the default, call the following code:

[[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:nil];
Copy the code

PS:

Pay attention to the name. The image name must match the CFBundleIconFiles configuration in info.plist. The setAlternateIconName: parameter needs to be the same as the key configured for CFBundleAlternateIcons in info. plist.

3. New solution: Add icon items within Assets

This scenario applies to Xcode13 and later versions, which cannot be configured in this way.

1. Add a new ICON to assets.xcassets:

Add a new set of ICONS as shown above and change the name of the ICON (for later use).

2. Allow multiple sets of ICONS in project Settings:

Select project ->Build Setting-> Search for Include All app Icon Assets and change to YES:

This is all configured.

The local test ICON is the same as the old method:

[[UIApplication sharedApplication] setAlternateIconName:@"Test" completionHandler:^(NSError * _Nullable error) {
    if (error ! = nil) {
        NSLog(@"set alternative icon error:%@", error.localizedDescription); }}];Copy the code

The parameter is the name of the newly added ICON group (Test in the screenshot). If a message is displayed indicating that the replacement is successful, the replacement is successful. Otherwise, an error is reported.

The principle of this implementation is to manually set info.plist and add ICON files in method 1, instead of directly reading ICON group in.xcassets, and automatically add configuration to info.plist because Include All app ICON assets is set to YES. Unlock a pack of ipa or open. The app you can see,, [email protected], [email protected], has been under the root directory of the inclusion, and the Info. The plist have CFBundleAlternateIcons/Test field:

4. Apple background switching ICON

After adding multiple sets of ICONS, only approved packages can switch ICONS in apple background. Because Apple will also review the alternative ICON to see if it meets the review rules. After the review, we can perform operations in the product optimization page on the following page:

For details about the test plan, see the Official Apple documentation: Configuration Solution – App Store Connect Help

Reserved issues: since this function is not available in my App, I do not know whether this function of icon switching can only be seen in App store of iOS15 version.

Reference Documents:

[1] Implementing alternate ICONS in iOS

[2] Xcode configures multiple sets of App ICONS — AppStore ICONS A/B Test practice