can any one help me how can i impliment alert for force update my iOS app. if new version is available on AppStore where in any Device have old or different version then i want to check if version is different then user update new version from AppStore. and how to get app information for my app.
Asked
Active
Viewed 852 times
0
-
Are you using third party or you have your custom view? – Jagat Dave Feb 16 '16 at 07:06
-
@JAGAT No i cant want to use any third party library. – Vvk Feb 16 '16 at 07:08
-
currently i have check version from our WS. but problem is that we have to update all time in WS for new version – Vvk Feb 16 '16 at 07:09
-
check this might be helpful http://stackoverflow.com/questions/6256748/check-if-my-app-has-a-new-version-on-appstore – kb920 Feb 16 '16 at 07:12
1 Answers
0
You can develop the function by comparing the version of the modern app with the version on the App Store.
enum VersionError: Error {
case invalidResponse, invalidBundleInfo
}
class AppStoreCheck {
static func isUpdateAvailable(completion: @escaping (Bool?, Error?) -> Void) throws -> URLSessionDataTask {
guard let info = Bundle.main.infoDictionary,
let currentVersion = info["CFBundleShortVersionString"] as? String,
let identifier = info["CFBundleIdentifier"] as? String,
let url = URL(string: your appstore url) else {
throw VersionError.invalidBundleInfo
}
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
do {
if let error = error { throw error }
guard let data = data else { throw VersionError.invalidResponse }
let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any]
guard let result = (json?["results"] as? [Any])?.first as? [String: Any], let version = result["version"] as? String else {
throw VersionError.invalidResponse
}
let verInt = NSString.init(string: version).intValue
let currentVerInt = NSString.init(string: currentVersion).intValue
completion(verInt > currentVerInt, nil)
} catch {
completion(nil, error)
}
}
task.resume()
return task
}
}
This class compares your app version with your app store version and reports it as a bool value.
You can call AppStoreCheck.isUpdateAvailable
and add the function through a bool value.

Hailey
- 302
- 1
- 7