mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* wxapp: add FileSystemManager * fix: add interface * uppercase interface name * add types react-native-audio * add types for baidumap * lint * add doc header non-npm package * add types: react-native-easy-upgrade * fix: options * fix * react-native-easy-update: add typescript version
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import RNEasyUpgrade from 'react-native-easy-upgrade';
|
|
import { Alert, Platform } from 'react-native';
|
|
|
|
const isAndroid = Platform.OS === 'android';
|
|
|
|
const easyUpgrade = new RNEasyUpgrade({
|
|
iOSAppId: '12345678',
|
|
downloadTitle: 'Download package',
|
|
downloadDescription: 'Packing downloading...',
|
|
downloadApkEnd: () => {
|
|
// eg: install apk
|
|
easyUpgrade.installApk();
|
|
},
|
|
onError: () => {
|
|
console.log('downloadApkError');
|
|
}
|
|
});
|
|
|
|
async function getUpdateInfo() {
|
|
const updateInfo = {
|
|
latestVersion: '3.0.0',
|
|
hasNewVersion: true,
|
|
apkUrl: 'http://{remoteApkDownloadUrl}'
|
|
};
|
|
if (isAndroid) {
|
|
try {
|
|
const resp = await fetch('http://{remoteUrl}/updateInfo.json');
|
|
return await resp.json();
|
|
} catch (error) {
|
|
return updateInfo;
|
|
}
|
|
} else {
|
|
return easyUpgrade.checkAppVersionIOS();
|
|
}
|
|
}
|
|
|
|
async function startUpgrade() {
|
|
const updateInfo = await getUpdateInfo();
|
|
if (updateInfo.hasNewVersion) {
|
|
Alert.alert(
|
|
'Find a new version: ' + updateInfo.latestVersion,
|
|
'Whether to upgrade app?',
|
|
[
|
|
{ text: 'Ask me later', onPress: () => console.log('Ask me later pressed') },
|
|
{
|
|
text: 'Upgrade', onPress: () => {
|
|
easyUpgrade.startAppUpdate(updateInfo.apkUrl);
|
|
}
|
|
},
|
|
],
|
|
);
|
|
}
|
|
}
|