# Updater ## Modules to Import ``` import client from 'libupdateclient.z.so' ``` ## Required Permissions None ## updater.getNewVersionInfo\(\) Obtains new version information. **Parameters**

Name

Type

Mandatory

Description

callback

Function

No

AsyncCallback<NewVersionInfo>

**Return Values**

Name

Type

Description

info

NewVersionInfo

New version information

**Example** ``` updater.getNewVersionInfo(info => { console.log("getNewVersionInfo success " + info.status); console.log(`info versionName = ` + info.result[0].versionName); console.log(`info versionCode = ` + info.result[0].versionCode); console.log(`info verifyInfo = ` + info.result[0].verifyInfo); )}; ``` ## updater.checkNewVersion\(\) Checks for a new version. **Parameters**

Name

Type

Mandatory

Description

callback

Function

No

AsyncCallback<NewVersionInfo>

**Return Values**

Name

Type

Description

info

NewVersionInfo

New version information

**Example** ``` updater.checkNewVersion(info => { console.log("checkNewVersion success " + info.status); console.log(`info versionName = ` + info.result[0].versionName); console.log(`info versionCode = ` + info.result[0].versionCode); console.log(`info verifyInfo = ` + info.result[0].verifyInfo); )}; ``` ## updater.download\(\) Downloads the new version and displays the download process. **Parameters** None **Return Values** None **Example** ``` updater.on("downloadProgress", progress => { console.log("downloadProgress on" + progress); console.log(`downloadProgress status: ` + progress.status); console.log(`downloadProgress percent: ` + progress.percent); )}; updater.download(); ``` ## updater.upgrade\(\) Starts an update. **Parameters** None **Return Values** None **Example** ``` updater.on("upgradeProgress", progress => { console.log("downloadProgress on" + progress); console.log(`downloadProgress status: ` + progress.status); console.log(`downloadProgress percent: ` + progress.percent); )}; updater.upgrade(); ``` ## updater.setUpdatePolicy\(\) Sets the update policy. **Parameters**

Name

Type

Mandatory

Description

policy

UpdatePolicy

Yes

Update policy

callback

Function

Yes

AsyncCallback<number>

**Return Values**

Name

Type

Description

result

number

  
**Example** ``` // Set the update policy. let policy = { autoDownload: false, autoDownloadNet: true, mode: 2, autoUpgradeInterval: [ 2, 3 ], autoUpgradeCondition: 2 } updater.setUpdatePolicy(policy, function(result) { console.log("setUpdatePolicy ", result) } ); ``` ## updater.getUpdatePolicy\(\) Checks the update policy. **Parameters**

Name

Type

Mandatory

Description

callback

Function

Yes

AsyncCallback<UpdatePolicy>

**Return Values**

Name

Type

Description

policy

UpdatePolicy

Update policy

**Example** ``` updater.getUpdatePolicy(policy => { console.log("getUpdatePolicy success", policy) }); ```