magic starSummarize by Aili

Tricking iOS Into Animating App Icons

๐ŸŒˆ Abstract

The article discusses how to trick iOS into animating app icons by abusing the Alternate App Icons system. It covers the problems with the default implementation, such as showing an alert to the user and not working in the background, and provides solutions to these issues using private APIs.

๐Ÿ™‹ Q&A

[01] Fixing Problem #1: Alerts

1. How does the author fix the issue of the alert being shown when changing the app icon? The author discovers that the setAlternateIconName method actually calls a private _setAlternateIconName method, which is responsible for showing the alert. By directly calling the _setAlternateIconName method using an Objective-C extension on UIApplication, the author is able to bypass the alert and change the app icon silently.

2. What is the key insight the author gains from decompiling the _setAlternateIconName method? The decompilation reveals that the method creates a new completion block that performs additional work, such as showing the alert, before calling the original completion block. By skipping this additional work and calling the _setAlternateIconName method directly, the author is able to avoid the alert.

[02] Fixing Problem #2: Background Usage

1. Why doesn't the app icon change when the app is in the background? The decompilation of the _setAlternateIconName method shows that it checks the application state, and only proceeds if the app is in the active state. This is likely because the underlying setAlternateIconName call to the LSApplicationProxy object may not work correctly in the background.

2. How does the author work around the background usage limitation? The author uses the debugger to patch out the check for the application state, effectively forcing the method to always behave as if the app is in the active state. This allows the app icon to be changed even when the app is in the background.

3. What private APIs does the author use to change the app icon without the background usage limitation? The author defines interfaces for LSApplicationProxy and LSBundleProxy, which allow him to directly call the private methods responsible for changing the app icon, without going through the public setAlternateIconName API.

[03] Animated Icons

1. How does the author implement the animated app icon effect? The author uses a CFRunLoopTimer to update the app icon at a rate of 30 frames per second. He calculates the current frame based on the time elapsed since the animation started, and then sets the app icon to the corresponding frame in the CFBundleAlternateIcons dictionary.

2. What challenges does the author face in achieving a smooth animation? The author notes that if the main thread is blocked, the timer may not fire every frame, causing the animation to lag. To work around this, he experiments with running the animation loop on the main thread instead of a timer, which provides better performance.

</output_format>

Shared by Daniel Chen ยท
ยฉ 2024 NewMotor Inc.