diff --git a/README.md b/README.md
index 6057c05e..30471e8b 100644
--- a/README.md
+++ b/README.md
@@ -325,7 +325,7 @@ export default config;
* [`reload()`](#reload)
* [`setMultiDelay(...)`](#setmultidelay)
* [`cancelDelay()`](#canceldelay)
-* [`getLatest()`](#getlatest)
+* [`getLatest(...)`](#getlatest)
* [`setChannel(...)`](#setchannel)
* [`unsetChannel(...)`](#unsetchannel)
* [`getChannel()`](#getchannel)
@@ -572,14 +572,18 @@ Cancels a {@link DelayCondition} to process an upd
--------------------
-### getLatest()
+### getLatest(...)
```typescript
-getLatest() => Promise
+getLatest(options?: GetLatestOptions | undefined) => Promise
```
Get Latest bundle available from update Url
+| Param | Type |
+| ------------- | ------------------------------------------------------------- |
+| **`options`** | GetLatestOptions
|
+
**Returns:** Promise<LatestVersion>
**Since:** 4.0.0
@@ -1054,6 +1058,13 @@ Returns null if no next bundle is set.
| **`download_url`** | string \| null
|
+#### GetLatestOptions
+
+| Prop | Type | Description | Default | Since |
+| ------------- | ------------------- | ----------------------------------------------------------------------------------------------- | ---------------------- | ----- |
+| **`channel`** | string
| The channel to get the latest version for The channel must allow 'self_assign' for this to work | undefined
| 6.8.0 |
+
+
#### ChannelRes
| Prop | Type | Description | Since |
diff --git a/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java b/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java
index 7473446d..7c2baff3 100644
--- a/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java
+++ b/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java
@@ -1058,10 +1058,17 @@ public void onResponse(
);
}
- public void getLatest(final String updateUrl, final Callback callback) {
+ public void getLatest(
+ final String updateUrl,
+ final String channel,
+ final Callback callback
+ ) {
JSONObject json;
try {
json = this.createInfoObject();
+ if (channel != null && json != null) {
+ json.put("defaultChannel", channel);
+ }
} catch (JSONException e) {
Log.e(TAG, "Error getLatest JSONException", e);
final JSObject retError = new JSObject();
diff --git a/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java b/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java
index 6e692cff..f0eeee29 100644
--- a/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java
+++ b/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java
@@ -860,9 +860,11 @@ public void list(final PluginCall call) {
@PluginMethod
public void getLatest(final PluginCall call) {
+ final String channel = call.getString("channel");
startNewThread(() ->
CapacitorUpdaterPlugin.this.implementation.getLatest(
CapacitorUpdaterPlugin.this.updateUrl,
+ channel,
res -> {
if (res.has("error")) {
call.reject(res.getString("error"));
@@ -965,6 +967,7 @@ public void run() {
try {
CapacitorUpdaterPlugin.this.implementation.getLatest(
CapacitorUpdaterPlugin.this.updateUrl,
+ null,
res -> {
if (res.has("error")) {
Log.e(
@@ -1257,6 +1260,7 @@ private Thread backgroundDownload() {
);
CapacitorUpdaterPlugin.this.implementation.getLatest(
CapacitorUpdaterPlugin.this.updateUrl,
+ null,
res -> {
final BundleInfo current =
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
diff --git a/ios/Plugin/CapacitorUpdater.swift b/ios/Plugin/CapacitorUpdater.swift
index 042fa4d9..4bf927e0 100644
--- a/ios/Plugin/CapacitorUpdater.swift
+++ b/ios/Plugin/CapacitorUpdater.swift
@@ -579,10 +579,13 @@ extension CustomError: LocalizedError {
)
}
- public func getLatest(url: URL) -> AppVersion {
+ public func getLatest(url: URL, channel: String?) -> AppVersion {
let semaphore: DispatchSemaphore = DispatchSemaphore(value: 0)
let latest: AppVersion = AppVersion()
- let parameters: InfoObject = self.createInfoObject()
+ var parameters: InfoObject = self.createInfoObject()
+ if let channel = channel {
+ parameters.defaultChannel = channel
+ }
print("\(self.TAG) Auto-update parameters: \(parameters)")
let request = AF.request(url, method: .post, parameters: parameters, encoder: JSONParameterEncoder.default, requestModifier: { $0.timeoutInterval = self.timeout })
diff --git a/ios/Plugin/CapacitorUpdaterPlugin.swift b/ios/Plugin/CapacitorUpdaterPlugin.swift
index cba44a45..9424ae9e 100644
--- a/ios/Plugin/CapacitorUpdaterPlugin.swift
+++ b/ios/Plugin/CapacitorUpdaterPlugin.swift
@@ -430,8 +430,9 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
}
@objc func getLatest(_ call: CAPPluginCall) {
+ let channel = call.getString("channel")
DispatchQueue.global(qos: .background).async {
- let res = self.implementation.getLatest(url: URL(string: self.updateUrl)!)
+ let res = self.implementation.getLatest(url: URL(string: self.updateUrl)!, channel: channel)
if res.error != nil {
call.reject( res.error!)
} else if res.message != nil {
@@ -748,7 +749,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
self.endBackGroundTask()
}
print("\(self.implementation.TAG) Check for update via \(self.updateUrl)")
- let res = self.implementation.getLatest(url: url)
+ let res = self.implementation.getLatest(url: url, channel: nil)
let current = self.implementation.getCurrentBundle()
if (res.message) != nil {
@@ -922,7 +923,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
}
let timer = Timer.scheduledTimer(withTimeInterval: TimeInterval(periodCheckDelay), repeats: true) { _ in
DispatchQueue.global(qos: .background).async {
- let res = self.implementation.getLatest(url: url)
+ let res = self.implementation.getLatest(url: url, channel: nil)
let current = self.implementation.getCurrentBundle()
if res.version != current.getVersionName() {
diff --git a/src/definitions.ts b/src/definitions.ts
index 2e89ef7e..e8c293ce 100644
--- a/src/definitions.ts
+++ b/src/definitions.ts
@@ -394,7 +394,7 @@ export interface CapacitorUpdaterPlugin {
* @throws {Error}
* @since 4.0.0
*/
- getLatest(): Promise;
+ getLatest(options?: GetLatestOptions): Promise;
/**
* Sets the channel for this device. The channel has to allow for self assignment for this to work.
@@ -748,6 +748,16 @@ export interface DelayCondition {
value?: string;
}
+export interface GetLatestOptions {
+ /**
+ * The channel to get the latest version for
+ * The channel must allow 'self_assign' for this to work
+ * @since 6.8.0
+ * @default undefined
+ */
+ channel?: string;
+}
+
export interface AppReadyResult {
bundle: BundleInfo;
}