diff --git a/.changeset/curly-zoos-end.md b/.changeset/curly-zoos-end.md
new file mode 100644
index 00000000..d016b048
--- /dev/null
+++ b/.changeset/curly-zoos-end.md
@@ -0,0 +1,5 @@
+---
+'@capawesome/capacitor-app-update': minor
+---
+
+feat: add `currentVersionName`, `availableVersionName`, ...
diff --git a/packages/app-update/README.md b/packages/app-update/README.md
index 2a2c3a47..80cd8d65 100644
--- a/packages/app-update/README.md
+++ b/packages/app-update/README.md
@@ -28,16 +28,25 @@ A working example can be found here: [robingenz/capacitor-plugin-demo](https://g
## Usage
```typescript
+import { Capacitor } from '@capacitor/core';
import { AppUpdate } from '@capawesome/capacitor-app-update';
const getCurrentAppVersion = async () => {
const result = await AppUpdate.getAppUpdateInfo();
- return result.currentVersion;
+ if (Capacitor.getPlatform() === 'android') {
+ return result.currentVersionCode;
+ } else {
+ return result.currentVersionName;
+ }
};
const getAvailableAppVersion = async () => {
const result = await AppUpdate.getAppUpdateInfo();
- return result.availableVersion;
+ if (Capacitor.getPlatform() === 'android') {
+ return result.availableVersionCode;
+ } else {
+ return result.availableVersionName;
+ }
};
const openAppStore = async () => {
@@ -203,18 +212,22 @@ Remove all listeners for this plugin.
#### AppUpdateInfo
-| Prop | Type | Description |
-| --------------------------------- | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| **`currentVersion`** | string
| Version code (Android) or CFBundleShortVersionString (iOS) of the currently installed app version. Only available on Android and iOS. |
-| **`availableVersion`** | string
| Version code (Android) or CFBundleShortVersionString (iOS) of the update. Only available on Android and iOS. |
-| **`availableVersionReleaseDate`** | string
| Release date of the update in ISO 8601 (UTC) format. Only available on iOS. |
-| **`updateAvailability`** | AppUpdateAvailability
| The app update availability. Only available on Android and iOS. |
-| **`updatePriority`** | number
| In-app update priority for this update, as defined by the developer in the Google Play Developer API. Only available on Android. |
-| **`immediateUpdateAllowed`** | boolean
| `true` if an immediate update is allowed, otherwise `false`. Only available on Android. |
-| **`flexibleUpdateAllowed`** | boolean
| `true` if a flexible update is allowed, otherwise `false`. Only available on Android. |
-| **`clientVersionStalenessDays`** | number
| Number of days since the Google Play Store app on the user's device has learnt about an available update if an update is available or in progress. Only available on Android. |
-| **`installStatus`** | FlexibleUpdateInstallStatus
| Flexible in-app update install status. Only available on Android. |
-| **`minimumOsVersion`** | string
| The minimum version of the operating system required for the app to run in iOS. Only available on iOS. |
+| Prop | Type | Description | Since |
+| --------------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
+| **`currentVersionName`** | string
| The current version name of the app. On **Android**, this is the `versionName` from the `android/app/build.gradle` file. On **iOS**, this is the `CFBundleShortVersionString` from the `Info.plist` file. Only available on Android and iOS. | 5.1.0 |
+| **`availableVersionName`** | string
| The available version name of the update. On **iOS**, this is the `CFBundleShortVersionString` from the `Info.plist` file. Only available on iOS. | 5.1.0 |
+| **`currentVersion`** | string
| Version code (Android) or CFBundleShortVersionString (iOS) of the currently installed app version. Only available on Android and iOS. | |
+| **`currentVersionCode`** | string
| The current version code of the app. On **Android**, this is the `versionCode` from the `android/app/build.gradle` file. On **iOS**, this is the `CFBundleVersion` from the `Info.plist` file. Only available on Android and iOS. | 5.1.0 |
+| **`availableVersion`** | string
| Version code (Android) or CFBundleShortVersionString (iOS) of the update. Only available on Android and iOS. | |
+| **`availableVersionCode`** | string
| The available version code of the update. On **Android**, this is the `versionCode` from the `android/app/build.gradle` file. Only available on Android. | 5.1.0 |
+| **`availableVersionReleaseDate`** | string
| Release date of the update in ISO 8601 (UTC) format. Only available on iOS. | |
+| **`updateAvailability`** | AppUpdateAvailability
| The app update availability. Only available on Android and iOS. | |
+| **`updatePriority`** | number
| In-app update priority for this update, as defined by the developer in the Google Play Developer API. Only available on Android. | |
+| **`immediateUpdateAllowed`** | boolean
| `true` if an immediate update is allowed, otherwise `false`. Only available on Android. | |
+| **`flexibleUpdateAllowed`** | boolean
| `true` if a flexible update is allowed, otherwise `false`. Only available on Android. | |
+| **`clientVersionStalenessDays`** | number
| Number of days since the Google Play Store app on the user's device has learnt about an available update if an update is available or in progress. Only available on Android. | |
+| **`installStatus`** | FlexibleUpdateInstallStatus
| Flexible in-app update install status. Only available on Android. | |
+| **`minimumOsVersion`** | string
| The minimum version of the operating system required for the app to run in iOS. Only available on iOS. | |
#### GetAppUpdateInfoOptions
diff --git a/packages/app-update/android/src/main/java/io/capawesome/capacitorjs/plugins/appupdate/AppUpdatePlugin.java b/packages/app-update/android/src/main/java/io/capawesome/capacitorjs/plugins/appupdate/AppUpdatePlugin.java
index e7e4c891..5ddcdbf4 100644
--- a/packages/app-update/android/src/main/java/io/capawesome/capacitorjs/plugins/appupdate/AppUpdatePlugin.java
+++ b/packages/app-update/android/src/main/java/io/capawesome/capacitorjs/plugins/appupdate/AppUpdatePlugin.java
@@ -79,8 +79,11 @@ public void getAppUpdateInfo(PluginCall call) {
return;
}
JSObject ret = new JSObject();
+ ret.put("currentVersionName", pInfo.versionName);
ret.put("currentVersion", String.valueOf(pInfo.versionCode));
+ ret.put("currentVersionCode", String.valueOf(pInfo.versionCode));
ret.put("availableVersion", String.valueOf(appUpdateInfo.availableVersionCode()));
+ ret.put("availableVersionCode", String.valueOf(appUpdateInfo.availableVersionCode()));
ret.put("updateAvailability", appUpdateInfo.updateAvailability());
ret.put("updatePriority", appUpdateInfo.updatePriority());
ret.put("immediateUpdateAllowed", appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE));
diff --git a/packages/app-update/ios/Plugin/AppUpdatePlugin.swift b/packages/app-update/ios/Plugin/AppUpdatePlugin.swift
index e6769602..5ec4b7ac 100644
--- a/packages/app-update/ios/Plugin/AppUpdatePlugin.swift
+++ b/packages/app-update/ios/Plugin/AppUpdatePlugin.swift
@@ -17,7 +17,8 @@ public class AppUpdatePlugin: CAPPlugin {
guard
let info = Bundle.main.infoDictionary,
let bundleId = info["CFBundleIdentifier"] as? String,
- let currentVersion = info["CFBundleShortVersionString"] as? String,
+ let currentVersionCode = info["CFBundleVersion"] as? String,
+ let currentVersionName = info["CFBundleShortVersionString"] as? String,
var lookupUrl = URL(string: "https://itunes.apple.com/lookup?bundleId=\(bundleId)&date=\(date)")
else {
call.reject("Invalid bundle info provided")
@@ -30,7 +31,7 @@ public class AppUpdatePlugin: CAPPlugin {
guard
let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any],
let result = (json["results"] as? [Any])?.first as? [String: Any],
- let availableVersion = result["version"] as? String,
+ let availableVersionName = result["version"] as? String,
let availableVersionReleaseDate = result["currentVersionReleaseDate"] as? String,
let minimumOsVersion = result["minimumOsVersion"] as? String
else {
@@ -38,13 +39,16 @@ public class AppUpdatePlugin: CAPPlugin {
return
}
var updateAvailability = AppUpdatePlugin.updateAvailabilityNotAvailable
- let updateAvailable = self.compareVersions(currentVersion, availableVersion) == .orderedDescending
+ let updateAvailable = self.compareVersions(currentVersionName, availableVersionName) == .orderedDescending
if updateAvailable {
updateAvailability = AppUpdatePlugin.updateAvailabilityAvailable
}
call.resolve([
- "currentVersion": currentVersion,
- "availableVersion": availableVersion,
+ "currentVersionName": currentVersionName,
+ "availableVersionName": availableVersionName,
+ "currentVersion": currentVersionName,
+ "currentVersionCode": currentVersionCode,
+ "availableVersion": availableVersionName,
"availableVersionReleaseDate": availableVersionReleaseDate,
"updateAvailability": updateAvailability,
"minimumOsVersion": minimumOsVersion
diff --git a/packages/app-update/src/definitions.ts b/packages/app-update/src/definitions.ts
index bbc3a709..36086e20 100644
--- a/packages/app-update/src/definitions.ts
+++ b/packages/app-update/src/definitions.ts
@@ -57,18 +57,68 @@ export interface GetAppUpdateInfoOptions {
}
export interface AppUpdateInfo {
+ /**
+ * The current version name of the app.
+ *
+ * On **Android**, this is the `versionName` from the `android/app/build.gradle` file.
+ * On **iOS**, this is the `CFBundleShortVersionString` from the `Info.plist` file.
+ *
+ * Only available on Android and iOS.
+ *
+ * @since 5.1.0
+ * @example "1.0.0"
+ */
+ currentVersionName: string;
+ /**
+ * The available version name of the update.
+ *
+ * On **iOS**, this is the `CFBundleShortVersionString` from the `Info.plist` file.
+ *
+ * Only available on iOS.
+ *
+ * @since 5.1.0
+ * @example "1.1.0"
+ */
+ availableVersionName?: string;
/**
* Version code (Android) or CFBundleShortVersionString (iOS) of the currently installed app version.
*
* Only available on Android and iOS.
+ *
+ * @deprecated On **Android**, use `currentVersionCode` instead. On **iOS**, use `currentVersionName` instead.
*/
currentVersion: string;
+ /**
+ * The current version code of the app.
+ *
+ * On **Android**, this is the `versionCode` from the `android/app/build.gradle` file.
+ * On **iOS**, this is the `CFBundleVersion` from the `Info.plist` file.
+ *
+ * Only available on Android and iOS.
+ *
+ * @since 5.1.0
+ * @example "1"
+ */
+ currentVersionCode: string;
/**
* Version code (Android) or CFBundleShortVersionString (iOS) of the update.
*
* Only available on Android and iOS.
+ *
+ * @deprecated On **Android**, use `availableVersionCode` instead. On **iOS**, use `availableVersionName` instead.
*/
availableVersion: string;
+ /**
+ * The available version code of the update.
+ *
+ * On **Android**, this is the `versionCode` from the `android/app/build.gradle` file.
+ *
+ * Only available on Android.
+ *
+ * @since 5.1.0
+ * @example "2"
+ */
+ availableVersionCode?: string;
/**
* Release date of the update in ISO 8601 (UTC) format.
*