Reputation: 3240
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:-
Upvotes: 0
Views: 25
Reputation: 1859
This is Robin, the maintainer of Capawesome. 👋
If I call the setBundle() then it always says "LiveUpdate.setBundle() is not implemented on ios". enter image description here
You should fix this first. It seems like the plugin was not installed properly. Take a look at the iOS Troubleshooting Guide regarding Plugin is not implemented to fix the problem.
I also noticed the following things:
ready()
method must be called at app startup as soon as your app is loaded and not before reload()
.setBundle(...)
(v6) or setNextBundle(...)
(v7) method before calling reload()
.Upvotes: 1