1import axios from 'axios'; 2import {compare} from 'compare-versions'; 3import DeviceInfo from 'react-native-device-info'; 4 5const updateList = [ 6 'https://gitee.com/maotoumao/testtt/raw/master/release/version.json', 7]; 8 9interface IUpdateInfo { 10 needUpdate: boolean; 11 data: { 12 version: string; 13 changeLog: string[]; 14 download: string[]; 15 }; 16} 17 18export default async function checkUpdate(): Promise<IUpdateInfo | undefined> { 19 const currentVersion = DeviceInfo.getVersion(); 20 for (let i = 0; i < updateList.length; ++i) { 21 try { 22 const rawInfo = (await axios.get(updateList[i])).data; 23 if (compare(rawInfo.version, currentVersion, '>')) { 24 return { 25 needUpdate: true, 26 data: rawInfo, 27 }; 28 } 29 } catch {} 30 } 31} 32