mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 22:20:39 +08:00
使用async写法
This commit is contained in:
@@ -50,67 +50,63 @@ export default class App extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
doUpdate = info => {
|
doUpdate = async info => {
|
||||||
downloadUpdate(info)
|
const hash = await downloadUpdate(info);
|
||||||
.then(hash => {
|
Alert.alert('提示', '下载完毕,是否重启应用?', [
|
||||||
Alert.alert('提示', '下载完毕,是否重启应用?', [
|
{
|
||||||
{
|
text: '是',
|
||||||
text: '是',
|
onPress: () => {
|
||||||
onPress: () => {
|
switchVersion(hash);
|
||||||
switchVersion(hash);
|
},
|
||||||
},
|
},
|
||||||
},
|
{text: '否'},
|
||||||
{text: '否'},
|
{
|
||||||
{
|
text: '下次启动时',
|
||||||
text: '下次启动时',
|
onPress: () => {
|
||||||
onPress: () => {
|
switchVersionLater(hash);
|
||||||
switchVersionLater(hash);
|
},
|
||||||
},
|
},
|
||||||
},
|
]);
|
||||||
]);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
Alert.alert('提示', '更新失败.');
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
checkUpdate = () => {
|
checkUpdate = async () => {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
// 开发模式不支持热更新,跳过检查
|
// 开发模式不支持热更新,跳过检查
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkUpdate(appKey)
|
let info;
|
||||||
.then(info => {
|
try {
|
||||||
if (info.expired) {
|
info = await checkUpdate(appKey);
|
||||||
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
|
} catch (err) {
|
||||||
{
|
console.warn(err);
|
||||||
text: '确定',
|
return;
|
||||||
onPress: () => {
|
}
|
||||||
info.downloadUrl && Linking.openURL(info.downloadUrl);
|
if (info.expired) {
|
||||||
},
|
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
|
||||||
|
{
|
||||||
|
text: '确定',
|
||||||
|
onPress: () => {
|
||||||
|
info.downloadUrl && Linking.openURL(info.downloadUrl);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
} else if (info.upToDate) {
|
||||||
|
Alert.alert('提示', '您的应用版本已是最新.');
|
||||||
|
} else {
|
||||||
|
Alert.alert(
|
||||||
|
'提示',
|
||||||
|
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
text: '是',
|
||||||
|
onPress: () => {
|
||||||
|
this.doUpdate(info);
|
||||||
},
|
},
|
||||||
]);
|
},
|
||||||
} else if (info.upToDate) {
|
{text: '否'},
|
||||||
Alert.alert('提示', '您的应用版本已是最新.');
|
],
|
||||||
} else {
|
);
|
||||||
Alert.alert(
|
}
|
||||||
'提示',
|
|
||||||
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,
|
|
||||||
[
|
|
||||||
{
|
|
||||||
text: '是',
|
|
||||||
onPress: () => {
|
|
||||||
this.doUpdate(info);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{text: '否'},
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.warn(err);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@@ -20,10 +20,7 @@ const {appKey} = _updateConfig[Platform.OS];
|
|||||||
异步函数checkUpdate可以检查当前版本是否需要更新:
|
异步函数checkUpdate可以检查当前版本是否需要更新:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
checkUpdate(appKey)
|
const info = await checkUpdate(appKey)
|
||||||
.then(info => {
|
|
||||||
})
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
返回的info有三种情况:
|
返回的info有三种情况:
|
||||||
@@ -97,38 +94,42 @@ class MyProject extends Component {
|
|||||||
Alert.alert('提示', '刚刚更新失败了,版本被回滚.');
|
Alert.alert('提示', '刚刚更新失败了,版本被回滚.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
doUpdate = info => {
|
doUpdate = async info => {
|
||||||
downloadUpdate(info).then(hash => {
|
try {
|
||||||
|
const hash = await downloadUpdate(info);
|
||||||
Alert.alert('提示', '下载完毕,是否重启应用?', [
|
Alert.alert('提示', '下载完毕,是否重启应用?', [
|
||||||
{text: '是', onPress: ()=>{switchVersion(hash);}},
|
{text: '是', onPress: ()=>{switchVersion(hash);}},
|
||||||
{text: '否',},
|
{text: '否',},
|
||||||
{text: '下次启动时', onPress: ()=>{switchVersionLater(hash);}},
|
{text: '下次启动时', onPress: ()=>{switchVersionLater(hash);}},
|
||||||
]);
|
]);
|
||||||
}).catch(err => {
|
} catch(err) {
|
||||||
Alert.alert('提示', '更新失败.');
|
Alert.alert('提示', '更新失败.');
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
checkUpdate = () => {
|
checkUpdate = async () => {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
// 开发模式不支持热更新,跳过检查
|
// 开发模式不支持热更新,跳过检查
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkUpdate(appKey).then(info => {
|
let info;
|
||||||
if (info.expired) {
|
try {
|
||||||
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
|
info = await checkUpdate(appKey);
|
||||||
{text: '确定', onPress: ()=>{info.downloadUrl && Linking.openURL(info.downloadUrl)}},
|
} catch (err) {
|
||||||
]);
|
|
||||||
} else if (info.upToDate) {
|
|
||||||
Alert.alert('提示', '您的应用版本已是最新.');
|
|
||||||
} else {
|
|
||||||
Alert.alert('提示', '检查到新的版本'+info.name+',是否下载?\n'+ info.description, [
|
|
||||||
{text: '是', onPress: ()=>{this.doUpdate(info)}},
|
|
||||||
{text: '否',},
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}).catch(err => {
|
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
if (info.expired) {
|
||||||
|
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
|
||||||
|
{text: '确定', onPress: ()=>{info.downloadUrl && Linking.openURL(info.downloadUrl)}},
|
||||||
|
]);
|
||||||
|
} else if (info.upToDate) {
|
||||||
|
Alert.alert('提示', '您的应用版本已是最新.');
|
||||||
|
} else {
|
||||||
|
Alert.alert('提示', '检查到新的版本'+info.name+',是否下载?\n'+ info.description, [
|
||||||
|
{text: '是', onPress: ()=>{this.doUpdate(info)}},
|
||||||
|
{text: '否',},
|
||||||
|
]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user