How to Remove a Terminated iOS App from the Recently Used List

Introduction to iOS App Management

As a developer creating automated testing suites for iOS applications, you may encounter scenarios where you need to terminate or reset an app to start fresh for the next test run. While Apple’s guidelines discourage terminating apps directly, there are legitimate reasons for doing so, such as in automated testing environments. In this article, we will explore methods to remove an killed app from the recently used list on iOS devices.

Understanding the Recently Used List

The recently used list is a feature of the iOS operating system that displays a list of applications that were most recently launched by the user. This list can be accessed by double-clicking the home button (on older iPhone models) or swiping up from the bottom of the screen with three fingers (on newer iPhone models). The recently used list is stored in memory and can be cleared programmatically.

Terminating an iOS App

There are several ways to terminate an iOS app:

  1. Exit(): This method, as mentioned in the original question, works by calling exit(0) from within the app’s code.
  2. Process Launch Args: You can modify the app’s launch arguments using a combination of CFURLRef and CFStringCreateWithCString.
  3. System Command: You can use the system command to terminate an app.

Removing an App from the Recently Used List

Unfortunately, there is no straightforward method for programmatically removing an app from the recently used list. However, you can try a few approaches:

Approach 1: Uninstall and Reinstall the App

This is not a recommended solution as it involves modifying the system’s state.

// Install a new version of the app
if (app_path) {
    unlink(app_path);
}

// Remove existing app data
if (existing_data_path) {
    remove(existing_data_path);
}

Approach 2: Clear App Launch History

You can clear an app’s launch history using LSApplicationWorkspaceGetLaunchHistory and CFIndexCreateAndCopy, but this only removes the app from memory, not from the system’s recently used list.

// Get the app's workspace
if (workspace_path) {
    CFIndex workspace_index = CFIndexCreateAndCopy(NULL, (CFURLRef)workspace_path);
    
    // Clear launch history
    if (launch_history_path) {
        unlink(launch_history_path);
        
        LaunchHistoryEntry *entry;
        for (CFIndex i = 0; i < workspace_index; i++) {
            entry = CFApplicationWorkspaceLaunchHistoryGetEntryAtIndex(NULL, workspace_index, i);
            
            // Clear the history
            if (entry->launchDate == NULL) {
                CFRelease(entry);
            }
        }
    }
}

Approach 3: Call a Private API

There is no documented private API for removing an app from the recently used list.

Conclusion

In conclusion, there are several approaches to remove an app from the recently used list on iOS devices. While some of these methods may work around certain limitations or edge cases, they are not always reliable and might require complex system modifications. As a developer, it is essential to weigh the pros and cons of each approach before choosing one.

Alternative Solutions

If you’re looking for alternative solutions to terminate an app in your automated testing suite, consider these options:

  • Jailbreaking: Although not allowed in this scenario, jailbreaking allows access to more low-level system features that can be used to manipulate the recently used list.
  • USB-only functionality: Utilize libraries such as libimobiledevice to interact with the iOS device using USB connectivity. These libraries provide a range of functions for managing apps, including terminating and resetting them.

By exploring these alternative solutions, you may find more effective ways to manage your automated testing suite and meet your specific requirements.

Future Work

In future articles, we can delve deeper into the technical details of each approach, discuss potential pitfalls and edge cases, and provide code examples for implementing these methods. Additionally, we will explore other aspects of iOS app management, such as managing background processes, handling notifications, and more.


Last modified on 2023-05-11