-
-
Notifications
You must be signed in to change notification settings - Fork 112
使用指南
xuexiangjys edited this page Jun 15, 2021
·
6 revisions
{
"Code": 0, //0代表请求成功,非0代表失败
"Msg": "", //请求出错的信息
"UpdateStatus": 1, //0代表不更新,1代表有版本更新,不需要强制升级,2代表有版本更新,需要强制升级
"VersionCode": 3, //编译版本号(唯一)
"VersionName": "1.0.2", //版本名(用于展示)
"ModifyContent": "1、优化api接口。\r\n2、添加使用demo演示。\r\n3、新增自定义更新服务API接口。\r\n4、优化更新提示界面。", //更新内容
"DownloadUrl": "https://raw.githubusercontent.com/xuexiangjys/XUpdate/master/apk/xupdate_demo_1.0.2.apk",// 文件下载地址
"ApkSize": 2048, //文件的大小(单位:kb)
"ApkMd5": "..." //md5值没有的话,就无法保证apk是否完整,每次都会重新下载。框架默认使用的是md5加密。
}
- 默认更新
FlutterXUpdate.checkUpdate(url: _updateUrl);
- 默认App更新 + 支持后台更新
FlutterXUpdate.checkUpdate(url: _updateUrl, supportBackgroundUpdate: true);
- 调整宽高比显示的版本更新
FlutterXUpdate.checkUpdate(url: _updateUrl, widthRatio: 0.6);
- 自动模式下版本更新, 如果需要完全无人干预,自动更新,需要root权限【静默安装需要】
FlutterXUpdate.checkUpdate(url: _updateUrl, isAutoMode: true);
- 下载时点击取消允许切换下载方式
FlutterXUpdate.checkUpdate(
url: _updateUrl,
overrideGlobalRetryStrategy: true,
enableRetry: true,
retryContent: "Github下载速度太慢了,是否考虑切换蒲公英下载?",
retryUrl: "https://www.pgyer.com/flutter_learn");
1.定义一个自定义的版本更新解析器
FlutterXUpdate.setCustomParseHandler(onUpdateParse: (String json) async {
//这里是自定义json解析
return customParseJson(json);
});
///将自定义的json内容解析为UpdateEntity实体类
UpdateEntity customParseJson(String json) {
AppInfo appInfo = AppInfo.fromJson(json);
return UpdateEntity(
hasUpdate: appInfo.hasUpdate,
isIgnorable: appInfo.isIgnorable,
versionCode: appInfo.versionCode,
versionName: appInfo.versionName,
updateContent: appInfo.updateLog,
downloadUrl: appInfo.apkUrl,
apkSize: appInfo.apkSize);
}
2.调用checkUpdate
方法,并设置isCustomParse
参数为true.
FlutterXUpdate.checkUpdate(url: _updateUrl3, isCustomParse: true);
///直接传入UpdateEntity进行更新提示
void checkUpdate8() {
FlutterXUpdate.updateByInfo(updateEntity: customParseJson(_customJson));
}
目前只支持主题色和顶部图片的自定义
1.配置顶部图片的资源路径, 路径: android/app/src/main/res/values/drawable
, 千万不要放到mipmap
文件下,否则资源将找不到。例如:
2.调用checkUpdate
方法,并设置themeColor
、 topImageRes
和 buttonTextColor
参数。
///自定义更新弹窗样式
void customPromptDialog() {
FlutterXUpdate.checkUpdate(url: _updateUrl, themeColor: '#FFFFAC5D', topImageRes: 'bg_update_top', buttonTextColor: '#FFFFFFFF');
}
【注意】: 当你使用 flutter build apk
命令打正式包的时候, 如果你使用了topImageRes
属性的话, 你需要配置 shrinkResources
为 false, 否则更新弹窗将会显示异常!
Name | Type | Default | Description |
---|---|---|---|
debug | bool | false | Whether Output log |
isPost | bool | false | Whether use post request |
isPostJson | bool | false | Whether post request upload json format |
timeout | int | 20000(ms) | Request response timeout |
isWifiOnly | bool | true | Whether update only under WiFi |
isAutoMode | bool | false | Whether to turn on automatic mode |
supportSilentInstall | bool | false | Whether to support silent installation requires that the device has root permission |
enableRetry | bool | false | In the process of downloading, if you click Cancel, whether the pop-up window for retrying to switch the download mode will pop up |
retryContent | String | '' | Try the prompt content of the prompt pop-up window again |
retryUrl | String | '' | Retrying prompt pop-up URL to jump after clicking |
params | Map | / | Public parameters to be set |
Name | Type | Default | Description |
---|---|---|---|
url | String | / | URL of version check |
params | Map | / | Parameters |
supportBackgroundUpdate | bool | false | Whether to support background updates |
isAutoMode | bool | false | Whether to turn on automatic mode |
isCustomParse | bool | false | Is it a custom resolution protocol |
themeColor | String | '' | Apply pop-up theme color |
topImageRes | String | '' | The name of the top picture resource in the pop-up window |
buttonTextColor | String | '' | The color of the button text |
widthRatio | double | / | Proportion of version update Prompter width to screen |
heightRatio | double | / | Proportion of version update Prompter height to screen |
overrideGlobalRetryStrategy | bool | false | Whether to override the global retry policy |
enableRetry | bool | false | In the process of downloading, if you click Cancel, whether the pop-up window for retrying to switch the download mode will pop up |
retryContent | String | '' | Try the prompt content of the prompt pop-up window again |
retryUrl | String | '' | Retrying prompt pop-up URL to jump after clicking |