mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-19 02:00:39 +08:00
bug fixed
This commit is contained in:
BIN
Example/testHotUpdate/js/assets/shezhi.png
Normal file
BIN
Example/testHotUpdate/js/assets/shezhi.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 696 B |
BIN
Example/testHotUpdate/js/assets/shezhi@2x.png
Normal file
BIN
Example/testHotUpdate/js/assets/shezhi@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
Example/testHotUpdate/js/assets/shezhi@3x.png
Normal file
BIN
Example/testHotUpdate/js/assets/shezhi@3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
@@ -7,39 +7,91 @@ import React, {
|
||||
AppRegistry,
|
||||
Component,
|
||||
StyleSheet,
|
||||
Platform,
|
||||
Text,
|
||||
View,
|
||||
Alert,
|
||||
TouchableOpacity,
|
||||
Linking,
|
||||
Image,
|
||||
} from 'react-native';
|
||||
|
||||
import {downloadFile, reloadUpdate} from 'react-native-update'
|
||||
import {
|
||||
isFirstTime,
|
||||
isRolledBack,
|
||||
packageVersion,
|
||||
currentVersion,
|
||||
checkUpdate,
|
||||
downloadUpdate,
|
||||
switchVersion,
|
||||
switchVersionLater,
|
||||
markSuccess,
|
||||
} from 'react-native-update';
|
||||
|
||||
import _updateConfig from '../update.json';
|
||||
const {appKey} = _updateConfig[Platform.OS];
|
||||
|
||||
class MyProject extends Component {
|
||||
componentWillMount(){
|
||||
if (isRolledBack) {
|
||||
Alert.alert('提示', '刚刚更新失败了,版本被回滚.');
|
||||
} else if (isFirstTime) {
|
||||
Alert.alert('提示', '这是当前版本第一次启动,是否要模拟启动失败?将回滚到上一版本', [
|
||||
{text: '是', onPress: ()=>{throw new Error('模拟启动失败,请重启应用')}},
|
||||
{text: '否', onPress: ()=>{markSuccess()}},
|
||||
]);
|
||||
};
|
||||
}
|
||||
doUpdate = info => {
|
||||
downloadUpdate(info).then(hash => {
|
||||
Alert.alert('提示', '下载完毕,是否重启应用?', [
|
||||
{text: '是', onPress: ()=>{switchVersion(hash);}},
|
||||
{text: '否',},
|
||||
{text: '下次启动时', onPress: ()=>{switchVersionLater(hash);}},
|
||||
]);
|
||||
}).catch(err => {
|
||||
Alert.alert('提示', '更新失败.');
|
||||
});
|
||||
};
|
||||
|
||||
checkUpdate = () => {
|
||||
checkUpdate(appKey).then(info => {
|
||||
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: '否',},
|
||||
]);
|
||||
}
|
||||
}).catch(err => {
|
||||
Alert.alert('提示', '检查更新失败.');
|
||||
});
|
||||
};
|
||||
|
||||
class testHotUpdate extends Component {
|
||||
render() {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.welcome}>
|
||||
Welcome to React Native!
|
||||
欢迎使用热更新服务
|
||||
</Text>
|
||||
<Image
|
||||
resizeMode = {'contain'}
|
||||
source = {require('./assets/shoucang.png')}
|
||||
style = {styles.image}
|
||||
/>
|
||||
<Text style={styles.instructions}>
|
||||
To get started, edit index.ios.js
|
||||
这是版本一 {'\n'}
|
||||
当前包版本号: {packageVersion}{'\n'}
|
||||
当前版本Hash: {currentVersion||'(空)'}{'\n'}
|
||||
</Text>
|
||||
<TouchableOpacity onPress={
|
||||
()=>{
|
||||
downloadFile({updateUrl:'http://7xjhby.com2.z0.glb.qiniucdn.com/ios1.ppk', hashName:'test'})
|
||||
}
|
||||
}>
|
||||
<TouchableOpacity onPress={this.checkUpdate}>
|
||||
<Text style={styles.instructions}>
|
||||
Press To DownloadFile
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity onPress={
|
||||
()=>{
|
||||
reloadUpdate({hashName:'test'})
|
||||
}
|
||||
}>
|
||||
<Text style={styles.instructions}>
|
||||
Press To Reload
|
||||
点击这里检查更新
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
@@ -64,6 +116,8 @@ const styles = StyleSheet.create({
|
||||
color: '#333333',
|
||||
marginBottom: 5,
|
||||
},
|
||||
image : {
|
||||
},
|
||||
});
|
||||
|
||||
AppRegistry.registerComponent('testHotUpdate', () => testHotUpdate);
|
||||
AppRegistry.registerComponent('testHotUpdate', () => MyProject);
|
||||
|
Reference in New Issue
Block a user