You can get all App info from iTunes store lookup API: http://itunes.apple.com/lookup?bundleId=YOUR_BUNDLE_ID
, in this you can get App version on App Store.
Make your design screen as you want to show your App users, Then compare your App version on App store & user's device, if both version not equal then show the update version screen.
Below is the complete implementation to compare app version on App store & device:
func isUpdateAvailableOnStore() -> Bool {
let infoDictionary = Bundle.main.infoDictionary
let bundleId = infoDictionary!["CFBundleIdentifier"] as! String
let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(bundleId)")
let infoData = try? Data(contentsOf: url!)
let appInfo = (try? JSONSerialization.jsonObject(with: infoData! , options: [])) as? [String: Any]
if let resultCount = appInfo!["resultCount"] as? Int, resultCount == 1 {
if let results = appInfo!["results"] as? [[String:Any]] {
if let appStoreVersion = results[0]["version"] as? String{
let currentAppVersion = infoDictionary!["CFBundleShortVersionString"] as? String
if !(appStoreVersion == currentAppVersion) {
return true
}
}
}
}
return false
}
Call this function in you func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
function of AppDelegate
.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Your code here
if self.isUpdateAvailableOnStore(){
// SHOW YOUR UPDATE SCREEN TO USER'S
}else{
// APP VERSION IS UPDATED ON DEVICE
}
return true
}