Since 2018 I open the XUpdate after, it has been iterated 14 versions, the monthly download capacity of 4k +, star amount Github also has 800+.
At present ecological XUpdate already contains native Android SDK , Flutter plug-in , version update back-office services , updated version management system . To be able to enrich its ecology, I decided to write a React-Native plug-ins.
Now I give react-native-xupdate-new
plug-address:
https://www.npmjs.com/package/react-native-xupdate-new
Show
- Default Update
- Support background update
- The screen aspect ratio limit display update
- Update
- Custom update prompt pop style
Quick Integration Guide
Note: This is embarrassing,
react-native-xupdate
has been the first to release someone else, I can only modify the publication namedreact-native-xupdate-new
Add dependent
npm install react-native-xupdate-new --save
link
react-native link react-native-xupdate-new
initialization
- Call the
XUpdate.init
method to initialize. - Call the
XUpdate.addErrorListener
method setting error monitoring.
import {XUpdate} from 'react-native-xupdate-new';
///初始化
initXUpdate() {
///设置初始化参数
let args = new InitArgs();
///是否输出日志
args.debug = true;
///post请求是否是上传json
args.isPostJson = false;
///是否只在wifi下才能进行更新
args.isWifiOnly = false;
///是否开启自动模式
args.isAutoMode = false;
///是否支持静默安装,这个需要设备有root权限
args.supportSilentInstall = false;
///在下载过程中,如果点击了取消的话,是否弹出切换下载方式的重试提示弹窗
args.enableRetry = false;
///初始化SDK
XUpdate.init(args).then(result => {
this.setState({
_message: '初始化成功:' + JSON.stringify(result),
});
}).catch(error => {
console.log(error);
this.setState({
_message: '初始化失败:' + error,
});
});
//设置自定义解析
XUpdate.setCustomParser({parseJson: this.customParser});
//设置错误监听
XUpdate.addErrorListener(this.errorListener);
}
Instructions for use
Version update Json format returned
{
"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加密。
}
new version update
- Default Update
checkUpdateDefault() {
let args = new UpdateArgs(_updateUrl);
XUpdate.update(args);
}
- Default App support background update update +
checkUpdateSupportBackground() {
let args = new UpdateArgs(_updateUrl);
args.supportBackgroundUpdate = true;
XUpdate.update(args);
}
- Adjust the aspect ratio of the display version update
checkUpdateRatio() {
let args = new UpdateArgs(_updateUrl);
args.widthRatio = 0.6;
XUpdate.update(args);
}
- In automatic mode version of the update, if necessary completely unattended, automatic updates, you need root privileges silent installation []
checkUpdateAutoMode() {
let args = new UpdateArgs(_updateUrl);
args.isAutoMode = true;
XUpdate.update(args);
}
- Click Cancel downloading allows you to switch to download mode
enableChangeDownLoadType() {
let args = new UpdateArgs(_updateUrl);
args.overrideGlobalRetryStrategy = true;
args.enableRetry = true;
args.retryContent = 'Github下载速度太慢了,是否考虑切换蒲公英下载?';
args.retryUrl = 'https://www.pgyer.com/flutter_learn';
XUpdate.update(args);
}
Custom Json parsing
1. Define an updated version of a custom parser
//设置自定义解析
XUpdate.setCustomParser({parseJson: this.customParser});
///Resolve the custom JSON content to the UpdateEntity entity class
customParser = (json) => {
let appInfo = JSON.parse(json);
return {
//必填
hasUpdate: appInfo['hasUpdate'],
versionCode: appInfo['versionCode'],
versionName: appInfo['versionName'],
updateContent: appInfo['updateLog'],
downloadUrl: appInfo['apkUrl'],
//选填
isIgnorable: appInfo['isIgnorable'],
apkSize: appInfo['apkSize'],
};
};
2. Set the isCustomParse
parameter to true.
///使用自定义json解析
customJsonParse() {
let args = new UpdateArgs(_updateUrl3);
args.isCustomParse = true;
XUpdate.update(args);
}
Directly into UpdateEntity update
///直接传入UpdateEntity进行更新提示
checkUpdateByUpdateEntity() {
let args = new UpdateArgs();
args.supportBackgroundUpdate = true;
XUpdate.updateByInfo(args, {
hasUpdate: AppInfo['hasUpdate'],
versionCode: AppInfo['versionCode'],
versionName: AppInfo['versionName'],
updateContent: AppInfo['updateLog'],
downloadUrl: AppInfo['apkUrl'],
//选填
isIgnorable: AppInfo['isIgnorable'],
apkSize: AppInfo['apkSize'],
});
}
Custom version update prompt pop style
Currently only supports custom color theme and top pictures
1. Configure the top of the picture resource path, path: android/app/src/main/res/values/drawable
Never put under mipmap file, otherwise the resources will be found. E.g:
2. Set themeColor
and topImageRes
parameters.
///自定义更新弹窗样式
customPromptDialog() {
let args = new UpdateArgs(_updateUrl);
args.themeColor = '#FFFFAC5D';
args.topImageRes = 'bg_update_top';
XUpdate.update(args);
}
Related link
- XUpdate a lightweight, high availability of the Android version of the update framework
- XUpdate use of documentation
- XUpdate of Flutter plugin
- XUpdate Admin Service
- XUpdate background management system