I want to check if there is an update on App Store for the app. To do so, I need to get the last version of the app in App Store.
For android (it's working fine):
actual class AppUpdateManager(private val context: Context) {
actual suspend fun checkForUpdate(): UpdateStatus = suspendCancellableCoroutine { cont ->
val appUpdateManager = AppUpdateManagerFactory.create(context)
val task = appUpdateManager.appUpdateInfo
task.addOnSuccessListener { info ->
if (info.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
cont.resume(UpdateStatus.UpdateAvailable)
} else {
cont.resume(UpdateStatus.NoUpdate)
}
}
task.addOnFailureListener {
cont.resume(UpdateStatus.Error(it.message ?: "Unknown error"))
}
}
}
For IOS, I have this but couldn't find the right way to do it:
actual class AppUpdateManager {
actual suspend fun checkForUpdate(): UpdateStatus {
val currentVersion =
NSBundle.mainBundle.infoDictionary?.get("CFBundleShortVersionString") as? String
val latestVersion = fetchLatestAppStoreVersion() // I need to implement this
return if (latestVersion != null && latestVersion > currentVersion.orEmpty()) {
UpdateStatus.UpdateAvailable
} else {
UpdateStatus.NoUpdate
}
}
private fun fetchLatestAppStoreVersion(): String? {
// Call iTunes Lookup API via NSURLSession (or use ktor client in iosMain)
return null // Placeholder
}`