Advanced Usage¶
If you want more control over the update process, you can use the following methods:
fetchLatestBundle()
: Check for updates without downloading them.downloadBundle()
: Download updates without applying them.setNextBundle()
: Set a new bundle as the next bundle to be applied.reload()
: Apply the new bundle immediately.
Check for updates¶
You can check for new bundles without downloading them by using the fetchLatestBundle()
method:
import { LiveUpdate } from "@capawesome/capacitor-live-update";
const checkForUpdates = async () => {
const result = await LiveUpdate.fetchLatestBundle();
if (result.bundleId) {
console.log("New update available: " + result.downloadUrl);
} else {
console.log("No update available");
}
};
This method returns all important information about the latest bundle, including the bundle ID and the download URL.
Download updates¶
You can then download bundles by using the downloadBundle()
method:
import { LiveUpdate } from "@capawesome/capacitor-live-update";
const downloadUpdate = async (bundleId: string, url: string) => {
await LiveUpdate.downloadBundle({
bundleId,
url
});
};
This method downloads the bundle, extracts the files, and moves them to the correct location in your app.
Apply updates¶
You can set a new bundle as the next bundle to be applied by using the setNextBundle()
method:
import { LiveUpdate } from "@capawesome/capacitor-live-update";
const setNextBundle = async (bundleId: string) => {
await LiveUpdate.setNextBundle({
bundleId,
});
};
If the bundle should be applied immediately, you can also call the reload()
method: