{"id":19765732,"url":"https://github.com/xuexiangjys/react-native-xupdate","last_synced_at":"2025-04-30T15:30:52.871Z","repository":{"id":38911814,"uuid":"247509129","full_name":"xuexiangjys/react-native-xupdate","owner":"xuexiangjys","description":"A React-Native plugin for XUpdate(Android Version Update Library)","archived":false,"fork":false,"pushed_at":"2023-12-15T02:48:16.000Z","size":1401,"stargazers_count":53,"open_issues_count":27,"forks_count":20,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-02-29T16:32:53.727Z","etag":null,"topics":["react","react-native","xupdate"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xuexiangjys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-15T16:49:50.000Z","updated_at":"2024-01-22T06:07:07.000Z","dependencies_parsed_at":"2023-02-05T03:30:50.569Z","dependency_job_id":null,"html_url":"https://github.com/xuexiangjys/react-native-xupdate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuexiangjys%2Freact-native-xupdate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuexiangjys%2Freact-native-xupdate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuexiangjys%2Freact-native-xupdate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xuexiangjys%2Freact-native-xupdate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xuexiangjys","download_url":"https://codeload.github.com/xuexiangjys/react-native-xupdate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224214860,"owners_count":17274696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","react-native","xupdate"],"created_at":"2024-11-12T04:19:15.819Z","updated_at":"2024-11-12T04:19:16.417Z","avatar_url":"https://github.com/xuexiangjys.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# react-native-xupdate\n\n[![Version](https://img.shields.io/badge/version-1.0.2-blue.svg)](https://www.npmjs.com/package/react-native-xupdate-new)\n[![Issue](https://img.shields.io/github/issues/xuexiangjys/react-native-xupdate.svg)](https://github.com/xuexiangjys/react-native-xupdate/issues)\n[![Star](https://img.shields.io/github/stars/xuexiangjys/react-native-xupdate.svg)](https://github.com/xuexiangjys/react-native-xupdate)\n\nA React-Native plugin for XUpdate(Android Version Update Library).\n\n## Getting started\n\n`$ npm install react-native-xupdate-new --save`\n\n### Mostly automatic installation\n\n`$ react-native link react-native-xupdate-new`\n\n### Manual installation\n\n\n#### iOS（Temporarily not supported）\n\n1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`\n2. Go to `node_modules` ➜ `react-native-xupdate-new` and add `RNXUpdate.xcodeproj`\n3. In XCode, in the project navigator, select your project. Add `libRNXUpdate.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`\n4. Run your project (`Cmd+R`)\u003c\n\n#### Android\n\n1. Open up `android/app/src/main/java/[...]/MainActivity.java`\n  - Add `import com.xuexiang.xupdate.RNXUpdatePackage;` to the imports at the top of the file\n  - Add `new RNXUpdatePackage()` to the list returned by the `getPackages()` method\n2. Append the following lines to `android/settings.gradle`:\n  \t```\n  \tinclude ':react-native-xupdate-new'\n  \tproject(':react-native-xupdate-new').projectDir = new File(rootProject.projectDir, \t'../node_modules/react-native-xupdate-new/android')\n  \t```\n3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:\n  \t```\n      compile project(':react-native-xupdate-new')\n  \t```\n\n\n## Usage\n\n### Initialization\n\n```\nimport {XUpdate} from 'react-native-xupdate-new';\n\n///初始化\ninitXUpdate() {\n    ///设置初始化参数\n    let args = new InitArgs();\n    ///是否输出日志\n    args.debug = true;\n    ///post请求是否是上传json\n    args.isPostJson = false;\n    ///是否只在wifi下才能进行更新\n    args.isWifiOnly = false;\n    ///是否开启自动模式\n    args.isAutoMode = false;\n    ///是否支持静默安装，这个需要设备有root权限\n    args.supportSilentInstall = false;\n    ///在下载过程中，如果点击了取消的话，是否弹出切换下载方式的重试提示弹窗\n    args.enableRetry = false;\n    \n    ///初始化SDK\n    XUpdate.init(args).then(result =\u003e {\n        this.setState({\n            _message: '初始化成功:' + JSON.stringify(result),\n        });\n    }).catch(error =\u003e {\n        console.log(error);\n        this.setState({\n            _message: '初始化失败:' + error,\n        });\n    });\n\n    //设置自定义解析\n    XUpdate.setCustomParser({parseJson: this.customParser});\n    //设置错误监听\n    XUpdate.addErrorListener(this.errorListener);\n}\n```\n\n### JSON Format\n\n```\n{\n  \"Code\": 0, //0代表请求成功，非0代表失败\n  \"Msg\": \"\", //请求出错的信息\n  \"UpdateStatus\": 1, //0代表不更新，1代表有版本更新，不需要强制升级，2代表有版本更新，需要强制升级\n  \"VersionCode\": 3,\n  \"VersionName\": \"1.0.2\",\n  \"ModifyContent\": \"1、优化api接口。\\r\\n2、添加使用demo演示。\\r\\n3、新增自定义更新服务API接口。\\r\\n4、优化更新提示界面。\",\n  \"DownloadUrl\": \"https://raw.githubusercontent.com/xuexiangjys/XUpdate/master/apk/xupdate_demo_1.0.2.apk\",\n  \"ApkSize\": 2048\n  \"ApkMd5\": \"...\"  //md5值没有的话，就无法保证apk是否完整，每次都会重新下载。框架默认使用的是md5加密。\n}\n```\n\n### CheckUpdate\n\n```\n    ///默认App更新\n    checkUpdateDefault() {\n        let args = new UpdateArgs(_updateUrl);\n        XUpdate.update(args);\n    }\n\n    ///默认App更新 + 支持后台更新\n    checkUpdateSupportBackground() {\n        let args = new UpdateArgs(_updateUrl);\n        args.supportBackgroundUpdate = true;\n        XUpdate.update(args);\n    }\n\n    ///调整宽高比\n    checkUpdateRatio() {\n        let args = new UpdateArgs(_updateUrl);\n        args.widthRatio = 0.6;\n        XUpdate.update(args);\n    }\n\n    ///强制更新\n    checkUpdateForce() {\n        let args = new UpdateArgs(_updateUrl2);\n        XUpdate.update(args);\n    }\n\n    ///自动模式, 如果需要完全无人干预，自动更新，需要root权限【静默安装需要】\n    checkUpdateAutoMode() {\n        let args = new UpdateArgs(_updateUrl);\n        args.isAutoMode = true;\n        XUpdate.update(args);\n    }\n\n    ///下载时点击取消允许切换下载方式\n    enableChangeDownLoadType() {\n        let args = new UpdateArgs(_updateUrl);\n        args.overrideGlobalRetryStrategy = true;\n        args.enableRetry = true;\n        args.retryContent = 'Github下载速度太慢了，是否考虑切换蒲公英下载？';\n        args.retryUrl = 'https://www.pgyer.com/flutter_learn';\n        XUpdate.update(args);\n    }\n\n    ///显示重试提示弹窗\n    showRetryDialogTip() {\n        XUpdate.showRetryUpdateTip('Github下载速度太慢了，是否考虑切换蒲公英下载？', 'https://www.pgyer.com/flutter_learn');\n    }\n```\n\n\n\n### Custom JSON Format\n\n1.Setting up a custom update parser\n\n```\n//设置自定义解析\nXUpdate.setCustomParser({parseJson: this.customParser});\n\n///Resolve the custom JSON content to the UpdateEntity entity class\ncustomParser = (json) =\u003e {\n    let appInfo = JSON.parse(json);\n    return {\n        //必填\n        hasUpdate: appInfo['hasUpdate'],\n        versionCode: appInfo['versionCode'],\n        versionName: appInfo['versionName'],\n        updateContent: appInfo['updateLog'],\n        downloadUrl: appInfo['apkUrl'],\n        //选填\n        isIgnorable: appInfo['isIgnorable'],\n        apkSize: appInfo['apkSize'],\n    };\n};\n```\n\n2.Set the parameter `isCustomParse` to true\n\n```\n///使用自定义json解析\ncustomJsonParse() {\n    let args = new UpdateArgs(_updateUrl3);\n    args.isCustomParse = true;\n    XUpdate.update(args);\n}\n```\n\n### Update By UpdateEntity Directly\n\n```\n///直接传入UpdateEntity进行更新提示\ncheckUpdateByUpdateEntity() {\n    let args = new UpdateArgs();\n    args.supportBackgroundUpdate = true;\n    XUpdate.updateByInfo(args, {\n        hasUpdate: AppInfo['hasUpdate'],\n        versionCode: AppInfo['versionCode'],\n        versionName: AppInfo['versionName'],\n        updateContent: AppInfo['updateLog'],\n        downloadUrl: AppInfo['apkUrl'],\n        //选填\n        isIgnorable: AppInfo['isIgnorable'],\n        apkSize: AppInfo['apkSize'],\n    });\n}\n```\n\n### Custom Update Prompt Style\n\n\u003e Currently, only theme color and top picture customization are supported!\n\n1.Configure top picture, Path: `android/app/src/main/res/values/drawable`, For example:\n\n![](https://github.com/xuexiangjys/flutter_xupdate/blob/master/example/art/6.png)\n\n2.Set the parameter `themeColor` and `topImageRes`\n\n```\n///自定义更新弹窗样式\ncustomPromptDialog() {\n    let args = new UpdateArgs(_updateUrl);\n    args.themeColor = '#FFFFAC5D';\n    args.topImageRes = 'bg_update_top';\n    XUpdate.update(args);\n}\n```\n\n## Property value\n\n### Initialization\n\nName | Type | Default | Description\n:-|:-:|:-:|:-\ndebug | bool | false | Whether Output log\nisPost | bool | false | Whether use post request\nisPostJson | bool | false | Whether post request upload json format\ntimeout | int | 20000(ms) | Request response timeout\nisWifiOnly | bool | true | Whether update only under WiFi\nisAutoMode | bool | false | Whether to turn on automatic mode\nsupportSilentInstall | bool | false | Whether to support silent installation requires that the device has root permission\nenableRetry | 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\nretryContent | String | '' | Try the prompt content of the prompt pop-up window again\nretryUrl | String | '' | Retrying prompt pop-up URL to jump after clicking\nparams | Map | / | Public parameters to be set\n\n### CheckUpdate\n\nName | Type | Default | Description\n:-|:-:|:-:|:-\nurl | String | / | URL of version check\nparams | Map | / | Parameters\nsupportBackgroundUpdate | bool | false | Whether to support background updates\nisAutoMode | bool | false | Whether to turn on automatic mode\nisCustomParse | bool | false | Is it a custom resolution protocol\nthemeColor | String | '' | Apply pop-up theme color\ntopImageRes | String | '' | The name of the top picture resource in the pop-up window\nbuttonTextColor | String | '' | The color of the button text\nwidthRatio | double | / | Proportion of version update Prompter width to screen\nheightRatio | double | / | Proportion of version update Prompter height to screen\noverrideGlobalRetryStrategy | bool | false | Whether to override the global retry policy\nenableRetry | 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\nretryContent | String | '' | Try the prompt content of the prompt pop-up window again\nretryUrl | String | '' | Retrying prompt pop-up URL to jump after clicking\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuexiangjys%2Freact-native-xupdate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxuexiangjys%2Freact-native-xupdate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuexiangjys%2Freact-native-xupdate/lists"}