33

How does the iOS app update mechanism work? How to tell user that application on Appstore has been updated?Do i have to write the functionality in the code to show the update popover or is it handled by Appstore to show notification to user that app has been updated. Is there any documentation provided by apple for this?

Prerna chavan
  • 3,179
  • 7
  • 35
  • 77
  • To which "update popover" do you refer? Normally, iOS makes the update available in the App Store app, with a notification badge indicating how many apps have updates. – Greg Hewgill Jul 02 '12 at 06:37
  • Is there any documentation for this provided by apple? – Prerna chavan Jul 02 '12 at 06:37
  • 2
    No. The only way to alert a user to an update, would be to manually send out some kind of notification over APNS when a new version of your app has been approved. – CodaFi Jul 02 '12 at 06:40
  • But when the device is synced with Appstore a badge is presented on the app on the device that app update is available. – Prerna chavan Jul 02 '12 at 06:43
  • The behaviour you are seeing is specific to that app, and is not part of the standard iOS behaviour. – Greg Hewgill Jul 03 '12 at 20:25
  • APNS would work, or you could have a service that asks the server for the latest version and compare it to the running version (which can be accessed as answered on http://stackoverflow.com/questions/458632/how-can-my-iphone-app-detect-its-own-version-number ) – Ege Akpinar Jan 16 '13 at 17:56

3 Answers3

29

You can use Harpy : this module trigger a UIAlertView when a new version of your app is available on the App Store.

Harpy is now depricated.Siren was ported from Harpy, as Siren and Harpy are maintained by the same developer. As of December 2018, Harpy has been deprecated in favor of Siren.

Taimoor Suleman
  • 1,588
  • 14
  • 29
MartinMoizard
  • 6,600
  • 12
  • 45
  • 75
  • 2
    I used it in one app, I'm happy with it – MartinMoizard Jun 13 '13 at 09:22
  • 1
    How to test Harpy before submitting the app into Apple Store? – Ganesh G Jan 12 '15 at 20:49
  • 5
    @G.Ganesh Change the version of your app in Xcode to a version that's less than the one in the App Store. If version 1.0.2 is in the App Store, then change the version of your app to 1.0.1 and build+run your app. If you see an alert, it works. You can now change the version back to whatever it is before you launch your app to the store. – ArtSabintsev Feb 24 '15 at 20:56
  • 2
    Use Siren for swift implementation of Harpy. Same developer. – kareem Jun 28 '16 at 09:07
29
  1. Apple provides an existing API to get the latest app information from your app on the App Store: http://itunes.apple.com/jp/lookup/?id=app_id

Ex: http://itunes.apple.com/jp/lookup/?id=1005582646

Ex for a US app: http://itunes.apple.com/lookup/?id=myAppIDNumberFromTheAppStore

Note that this is separate from the App Store Connect API. If you use that, you'll need to generate a token before making the request. Please review the documentation on the API first or you will get a response with empty results.

https://developer.apple.com/documentation/appstoreconnectapi

https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests

The response of the iTunes API has a "version" field that is within the "results" field. It has the version number of the latest build on the App Store.

In AppDelegate->didFinishLaunchingWithOptions, you can call the above API.

  1. The way to get current version on user's device:

Obj-C.

NSString *currentAppVersion = [[[NSBundle mainBundle]
    infoDictionary] objectForKey:@"CFBundleShortVersionString"];

Swift (4.2)

var currentAppVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String

Now you can compare the version number from 1 and 2 to show an alert or notification to the user when there is an updated app on the App Store.

Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
Dinh Viet Phu
  • 310
  • 3
  • 8
1

You can find the solution here. Write this function in your home viewController.

func viewDidLoad()
{
    DispatchQueue.global().async {
        do {
            let update = try self.isUpdateAvailable()
            DispatchQueue.main.async {
                if update{
                    self.popupUpdateDialogue();
                    //you can show a popup to notify the user
                }
            }
        } catch {
            print(error)
        }
    }
}

func isUpdateAvailable() throws -> Bool {
    guard let info = Bundle.main.infoDictionary,
          let currentVersion = info["CFBundleShortVersionString"] as? String,
          let identifier = info["CFBundleIdentifier"] as? String,
          let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(identifier)") else {
        throw VersionError.invalidBundleInfo
    }
    let data = try Data(contentsOf: url)
    guard let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any] else {
        throw VersionError.invalidResponse
    }
    if let result = (json["results"] as? [Any])?.first as? [String: Any], let version = result["version"] as? String {
        appStoreVersion = version
        return version != currentVersion
    }
    throw VersionError.invalidResponse
}
Saravanan
  • 113
  • 1
  • 11