iOS App icon logo replacement (local replacement)

1. All major shopping platforms change their App Icon icons during holidays

There are usually two ways: 1. Every time you change a new icon, you need to go to the AppStore again;

                                2. Reserve the icons that need to be replaced in the future in the project, and use the api to trigger (or automatically replace according to local time)

The two methods have their own advantages and disadvantages. The first disadvantage: you need to go to the AppStore every time, which is a bit troublesome; the advantage: but you can ensure that the icons on the AppStore are also up-to-date

                          The second type has disadvantages: you need to design the icons in the future, and the icons on the AppStore will not be updated. Pros: You don’t need to put it on the shelves frequently, you only need to bury the icon and change it at any time.

Everyone knows the first method, now let's talk about the second.

Apple officially supports dynamic replacement of application logos starting from iOS10.3, and the newly added APIs are as follows

 

One: Add the Icon icon (picture) that needs to be replaced

Note: Do not put the added icon in the Assets.xcassets file; put it in the file directory, as shown below (I named the picture replaceIcon)

Two: Configure info.plist information

2.1 Add Icon files (iOS 5), the type is Dictionary

    Note: The full name is Icon files (iOS 5), including iOS5 in brackets

2.2 Add CFBundleAlternateIcons under Icon files (iOS 5), the type is Dictionary

2.3 Add changeIcon1 under CFBundleAlternateIcons, the type is Dictionary

Note: changeIcon1 is the name of the file storing the picture, the name can be chosen randomly. In this article, only here can be named casually, and the others are Apple's fixed class names

2.4. Add CFBundleIconFiles under changeIcon1, the type is Array

2.5. Add an item0 under CFBundleIconFiles, the type is String type. Enter the name of the replacement picture here (replaceIcon in step 1)

Here you can also create multiple replacement image files changeIcon2, changeIcon3

 3. Use

Write the following code where the picture needs to be replaced: changeIcon1 in the code is the name of the picture file created in step 2 --> 2.3

    if ([UIApplication sharedApplication].supportsAlternateIcons) //To determine whether to support changing application icons {

        [[UIApplication sharedApplication] setAlternateIconName:@"changeIcon1" completionHandler:^(NSError * _Nullable error) {

            if (error)

            {

                NSLog(@"An error occurred in changing the app icon: %@", error);

            }else{

                NSLog(@"replace app icon successfully");

            }

        }];

    }

 4. Optimization

After completing the above three steps, the icon replacement process is basically calculated, but when calling the icon replacement method (step 3), the system will pop up a pop-up window to inform the user that the replacement has been completed, as shown in the figure below. Such an experience is very unfriendly.

 

Now let's find a way to get rid of this pop-up window

Guess you like

Origin blog.csdn.net/wyz670083956/article/details/127126570