Skip to content

appInit Version Update Tool

appInit is a utility class used for managing version updates in UniApp applications.

Interface Definitions

UpdateVersionOptions

Parameter NameTypeRequiredDescription
versionstringYesLatest version number (e.g., 1.0.1)
descriptionstringYesDescription of update content
urlstringYesAndroid update package download address (supports .apk and .wgt)
forcebooleanNoWhether to force update, default false
iosStoreUrlstringNoiOS App Store jump address
onProgress(progress: OnProgressDownloadResult) => voidNoDownload progress callback
beforeUpdate(version: string) => boolean | voidNoCallback before update, return false to prevent update
onSuccess() => voidNoCallback after successful update
onFail(error: string) => voidNoCallback after update failure
onConfirm() => voidNoCallback when the user clicks the confirm button
onCancel() => voidNoCallback when the user clicks the cancel button

OnProgressDownloadResult

Parameter NameTypeDescription
progressnumberDownload progress percentage (0-100)
totalBytesWrittennumberNumber of bytes written
totalBytesExpectedToWritenumberExpected total number of bytes

Function List

updateVersion(options) => void

Check and execute application version updates, supporting iOS and Android platforms.

Parameters

Parameter NameTypeRequiredDefaultDescription
optionsUpdateVersionOptionsYes-Update configuration options

Return Value

TypeDescription
voidNo return value

Example

typescript
import { appInit } from '@hy-app/ui';

appInit.updateVersion({
    version: '1.0.1',
    description: '1. Fixed known bugs\n2. Optimized performance',
    url: 'https://example.com/app.apk',
    force: true,
    onProgress: (res) => {
        console.log(`Download progress: ${res.progress}%`);
    },
});

compareVersion(serverVersion, localVersion) => number

Compare the sizes of two version numbers.

Parameters

Parameter NameTypeRequiredDefaultDescription
serverVersionstringYes-Server version number
localVersionstringYes-Local version number

Return Value

TypeDescription
number1 Server version is higher, 0 Versions are the same, -1 Local version is higher

Example

typescript
import { appInit } from '@hy-app/ui';

const result = appInit.compareVersion('1.2.0', '1.1.9');

if (result === 1) {
    // Needs to be updated
}

downloadApp(downloadUrl, callbacks) => void

Download the update package, supporting .wgt and .apk formats.

Parameters

Parameter NameTypeRequiredDefaultDescription
downloadUrlstringYes-Download address
callbacksNo-Callback functions

Return Value

TypeDescription
voidNo return value