In the last article, we looked at how to use the new App icon in detail and made a small Demo. Although it’s now possible to change App ICONS dynamically, the “friendly tips” apple gives each time an icon is changed are not “friendly” to users or developers. Officials gave no can’t play any box, the method of App ICONS for apple, after all, is an important part of the audit, if let the developer after the shelves without prompting the user to modify the icon, can cause a bad user experience, so apple will notify users when using this API bounced the App icon modified (personal).
But today we want to talk about how to get around this limitation (after all, developers are not stupid enough to just change their ICONS at 🤣).
This series of articles
- IOS Dynamic App icon Replacement (1) : Basic use
- IOS Dynamic App icon Replacement (2) : No dialog box is displayed. Replace the App icon
- IOS Dynamic App icon replacement (3) : Dynamically download the App icon for replacement
The Demo presentation
Demo address: github.com/maybeisyi/C…
The corresponding project of this article is: DynamicAppIcon (ii)
As you can see in the Demo, we can now modify the App icon without popping the box. Once this feature is implemented, some interesting little functions can have a good user experience: switching between day/night mode, switching between App main colors and App ICONS at the same time.
Here’s how to break apple’s limits.
What is a pop frame
Let’s look at the nature of the cartridge
Look at the popbox in the original Demo, this popbox looks a lot like UIAlertController. Let’s examine this popbox:
You can see that the popbox is the private _UIAlertControllerView class. Let’s compare the system UIAlertController:
So when you change your App, the popbox is UIAlertController, but the controls on it are different. (We can also add any control to UIAlertController)
Interceptor box
If we know that the bullet box is UIAlertController, then we naturally think of, the bullet box is passed by ViewController presentViewController: animated: completion: the pop-up. Then we can use Method Swizzling hook to prevent it from popping:
#import "UIViewController+Present.h" #import @implementation UIViewController (Present) + (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Method presentM = class_getInstanceMethod(self.class, @selector(presentViewController:animated:completion:)); Method presentSwizzlingM = class_getInstanceMethod(self.class, @selector(dy_presentViewController:animated:completion:)); // Swaps methods implement method_exchangeImplementations(presentM, presentSwizzlingM); }); } - (void)dy_presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion { if ([viewControllerToPresent isKindOfClass:[UIAlertController class]]) { NSLog(@"title : %@",((UIAlertController *)viewControllerToPresent).title); NSLog(@"message : %@",((UIAlertController *)viewControllerToPresent).message); UIAlertController *alertController = (UIAlertController *)viewControllerToPresent; if (alertController.title == nil && alertController.message == nil) { return; } else { [self dy_presentViewController:viewControllerToPresent animated:flag completion:completion]; return; } } [self dy_presentViewController:viewControllerToPresent animated:flag completion:completion]; } @endCopy the code
This code is the exchange of the UIViewController presentViewController: animated: completion: method. By printing the characteristics of UIAlertController, we can find that there is no title and message in the pop-up box when the App icon is changed. However, we generally use UIAlertController with title and message. After all, it will not play a blank box for the user to play.
Therefore, in this method, the pop-up box when the App icon is changed can be captured by judging the title and message, and the return can be directly returned.
conclusion
In fact, there is nothing that can’t be done with dynamic features on the interface. Since Apple has disclosed dynamic APIS, we can understand or even transform what we want through dynamic methods, such as how system controls are implemented. Apple’s “spec” doesn’t stop developers at the app level, and dynamic features (such as proprietary methods) can’t be abused, because reviewers are the dad.
Although it is currently possible to replace App ICONS without the user feeling them, the alternative ICONS must be pre-placed in the project and specified in info.plist. This greatly limits the dynamics of changing ICONS: For example, one day we wanted to launch a new theme and the corresponding App icon, but the new App icon was not pre-included in the project’s main bundle or specified in info.plist, so we could not launch the new App icon without launching the new version, hence the third article.
The third article: “iOS dynamic change App icon (three) : dynamic download App icon replacement” in the short term should not be implemented, specific reasons will be explained in the article.