paint-brush
Old is Gold: Save and Rollback to Previous App Versions on the AppStoreby@micci
465 reads
465 reads

Old is Gold: Save and Rollback to Previous App Versions on the AppStore

by Misha K.July 21st, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In the [previous article], we found a way to publish older builds of an app to TestFlight. The issue with this method is that it's difficult to determine which build was uploaded to the app store. In this article, I will share a method that does not depend on developer builds and can be utilized to revert any App Store application.
featured image - Old is Gold: Save and Rollback to Previous App Versions on the AppStore
Misha K. HackerNoon profile picture

In the previous article, we found a way to publish older builds of an app to TestFlight.

The issue with this method is that it's difficult to determine which build was uploaded to the app store, and you must reupload all necessary versions every 90 days.


In this article, I will share a method that does not depend on developer builds and can be utilized to revert any App Store application. However, it necessitates preparation on your part.


We will use your personal Apple ID to download an IPA file from the App Store for each new version. This way, you'll be able to install any of the previously stored versions at any time in the future.


Dependencies

To begin, it is necessary to install all the required tools.


brew install ipatool
brew install ideviceinstaller


ipatool – allows you to search for iOS apps on the App Store and download a copy of the app package, known as an ipa file.


ideviceinstaller – allows interaction with the app installation service of an iOS device.


Basic usage

Right after authorization:

ipatool auth login --email [email protected]


You will be able to download your app using:

ipatool download --bundle-identifier <app-bundle-id> -o appname_latest.ipa


Then, you will be able to install the app on your iPhone by connecting it to your computer via cable and running the command:

ideviceinstaller --install appname_latest.ipa


Monitor and download new versions as they appear on App Store

As for monitoring new versions on the App Store, a simple script could be written that runs at specified intervals, checking for updates to your app. This script could then download any new versions that are detected, adding them to your stored versions.


#!/bin/bash

BUNDLE_ID='your-app-bundle-id'
EMAIL='[email protected]'

DIRECTORY='older_versions'
mkdir -p $DIRECTORY

CURRENT_SIZE=$(stat -f%z "$DIRECTORY/appname_latest.ipa" 2>/dev/null)
ipatool download --bundle-identifier $BUNDLE_ID -o appname_new.ipa
NEW_SIZE=$(stat -f%z "appname_new.ipa" 2>/dev/null)

# Compare and update if new version available
if [ "$CURRENT_SIZE" != "$NEW_SIZE" ]; then
    echo "New version found, storing the old version"
    TIMESTAMP=$(date +%Y%m%d%H%M%S)
    mv "$DIRECTORY/appname_latest.ipa" "$DIRECTORY/appname_$TIMESTAMP.ipa"
    mv appname_new.ipa "$DIRECTORY/appname_latest.ipa"
else
    echo "No new version found"
    rm appname_new.ipa
fi


To run this script every week, we can use cron. Run crontab -e to open the cron configuration in your default editor, then add a new line like this:

0 0 * * 0 /path/to/your/script.sh


Rollback

To rollback to a previous version, follow these steps:


  1. Connect your iOS device to your computer.

  2. Locate the IPA file of the version you want to install from your stored versions.

  3. Run the command ideviceinstaller --install /path/to/your_app/older_versions/appname_timestamp.ipa in the terminal.


Your iOS device should now have the older version of your application installed.

As a word of caution, remember that this method should primarily be used for testing and development purposes. Rolling back to older versions could pose security risks or operational instability.


Installing to a phone with a different Apple ID

One thing to keep in mind when installing these stored versions on a device with a different Apple ID is that Apple's DRM uses .sinf files to ensure that apps are used by the Apple ID that originally downloaded them.


This means that while the stored versions can be installed on any device, they may not run correctly if the Apple ID doesn't match.


If you attempt to open the app, your iPhone will display an alert requesting that you enter the Apple ID and password associated with the account used to download the IPA. After that, you should be able to use the app as normal.


Conclusion

The method we've just explored allows us to maintain a version history of an application, which can be particularly useful for QA or regression testing. Instead of relying on maintaining different builds, we can systematically and continuously download versions directly from the App Store and store them for future reference. This provides us with a much more sustainable and straightforward approach to app version management.


In conclusion, managing App Store versions directly can be an effective strategy for app development and testing, particularly when combined with traditional version control systems. While it requires some additional setup and maintenance, it provides a straightforward method for keeping track of App Store versions, which can be particularly valuable in complex or long-term projects.