App-versions.php
Код: Выделить всё
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)
}
}
})();
< /code>
Проблемы:-< /p>
- LiveUpdate.getCurrentBundle (); Всегда возвращает {bundleid: null} для самостоятельного. >
- Очень сложно узнать, когда мне следует загрузить новый пакет, потому что прикладная пакет всегда нулевой. Ошибка «Пакет уже существует». Мой дальнейший скрипт не выполнил (т. Е. Готово, перезагрузить).
Подробнее здесь: https://stackoverflow.com/questions/794 ... ices-capac
Мобильная версия