I have a Vue.js-based application and I am using Capacitor to build the mobile app.
The mobile application is working fine as expected but I am facing an issue with using the live-update plugin using self-hosted not capawesome cloud.
I have read the documentation from here
To get the latest version, I have the following file on my self-hosted server
app-versions.php
<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token , Authorization');
$data = [
["version" => "8.1.27"],
["version" => "8.1.28"],
];
header('Content-type: application/json');
echo json_encode($data);
?>
based on this, I have the following code in my main.js
import { LiveUpdate } from '@capawesome/capacitor-live-update';
const getBundleInfo = async () => {
try {
const request = await fetch("https://example.com/app-versions.php", {
method: "GET",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
}
})
const result = await request.json();
let appVersion = version;
if (result.length > 0) {
appVersion = result[result.length - 1].version
alert("Latest version is: " + appVersion)
}
return appVersion;
} catch (error) {
alert(error)
}
}
(async () => {
if (Capacitor.isNativePlatform()) {
try {
const result = await LiveUpdate.getCurrentBundle();
// this result is always {bundleId: null}
} catch (error) {
alert(error)
}
try {
const version = await getBundleInfo();
await LiveUpdate.downloadBundle({
url: `https://example.com/build-v${version}.zip`,
bundleId: version,
});
await LiveUpdate.ready();
await LiveUpdate.reload();
} catch (error) {
alert(error)
}
}
})();
Issues:-
- The LiveUpdate.getCurrentBundle(); always returns {bundleId: null} for self-hosted.
- If I call the setBundle() then it always says “LiveUpdate.setBundle() is not implemented on ios”.
- It is very difficult to know when should I download the new bundle because the applied bundle is always null.
- I rely on the exception of the downloadBundle function so when I get the error “Bundle already exists” my further script didn’t execute(i.e ready, reload).