1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-18 22:20:39 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

使用async写法

This commit is contained in:
sunnylqm
2019-10-05 12:15:00 +08:00
parent 92ec598d2a
commit a87763fdd0
2 changed files with 75 additions and 78 deletions

View File

@@ -50,9 +50,8 @@ export default class App extends Component {
);
}
}
doUpdate = info => {
downloadUpdate(info)
.then(hash => {
doUpdate = async info => {
const hash = await downloadUpdate(info);
Alert.alert('提示', '下载完毕,是否重启应用?', [
{
text: '是',
@@ -68,19 +67,20 @@ export default class App extends Component {
},
},
]);
})
.catch(err => {
Alert.alert('提示', '更新失败.');
});
};
checkUpdate = () => {
checkUpdate = async () => {
if (__DEV__) {
// 开发模式不支持热更新,跳过检查
return;
}
checkUpdate(appKey)
.then(info => {
let info;
try {
info = await checkUpdate(appKey);
} catch (err) {
console.warn(err);
return;
}
if (info.expired) {
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
{
@@ -107,10 +107,6 @@ export default class App extends Component {
],
);
}
})
.catch(err => {
console.warn(err);
});
};
render() {

View File

@@ -20,10 +20,7 @@ const {appKey} = _updateConfig[Platform.OS];
异步函数checkUpdate可以检查当前版本是否需要更新
```javascript
checkUpdate(appKey)
.then(info => {
})
const info = await checkUpdate(appKey)
```
返回的info有三种情况
@@ -97,23 +94,30 @@ class MyProject extends Component {
Alert.alert('提示', '刚刚更新失败了,版本被回滚.');
}
}
doUpdate = info => {
downloadUpdate(info).then(hash => {
doUpdate = async info => {
try {
const hash = await downloadUpdate(info);
Alert.alert('提示', '下载完毕,是否重启应用?', [
{text: '是', onPress: ()=>{switchVersion(hash);}},
{text: '否',},
{text: '下次启动时', onPress: ()=>{switchVersionLater(hash);}},
]);
}).catch(err => {
} catch(err) {
Alert.alert('提示', '更新失败.');
});
}
};
checkUpdate = () => {
checkUpdate = async () => {
if (__DEV__) {
// 开发模式不支持热更新,跳过检查
return;
}
checkUpdate(appKey).then(info => {
let info;
try {
info = await checkUpdate(appKey);
} catch (err) {
console.warn(err);
return;
}
if (info.expired) {
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
{text: '确定', onPress: ()=>{info.downloadUrl && Linking.openURL(info.downloadUrl)}},
@@ -126,9 +130,6 @@ class MyProject extends Component {
{text: '否',},
]);
}
}).catch(err => {
console.warn(err);
});
};
render() {
return (