避免在debug模式下调用
This commit is contained in:
parent
c40bf71032
commit
08ac354ba5
@ -49,6 +49,10 @@ export default class App extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
checkUpdate = () => {
|
checkUpdate = () => {
|
||||||
|
if (__DEV__) {
|
||||||
|
// 开发模式不支持热更新,跳过检查
|
||||||
|
return;
|
||||||
|
}
|
||||||
checkUpdate(appKey).then(info => {
|
checkUpdate(appKey).then(info => {
|
||||||
if (info.expired) {
|
if (info.expired) {
|
||||||
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
|
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
|
||||||
@ -63,7 +67,7 @@ export default class App extends Component {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
Alert.alert('提示', '检查更新失败.');
|
console.warn(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ import _updateConfig from './update.json';
|
|||||||
const {appKey} = _updateConfig[Platform.OS];
|
const {appKey} = _updateConfig[Platform.OS];
|
||||||
|
|
||||||
class MyProject extends Component {
|
class MyProject extends Component {
|
||||||
componentWillMount(){
|
componentDidMount(){
|
||||||
if (isFirstTime) {
|
if (isFirstTime) {
|
||||||
Alert.alert('提示', '这是当前版本第一次启动,是否要模拟启动失败?失败将回滚到上一版本', [
|
Alert.alert('提示', '这是当前版本第一次启动,是否要模拟启动失败?失败将回滚到上一版本', [
|
||||||
{text: '是', onPress: ()=>{throw new Error('模拟启动失败,请重启应用')}},
|
{text: '是', onPress: ()=>{throw new Error('模拟启动失败,请重启应用')}},
|
||||||
@ -109,6 +109,10 @@ class MyProject extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
checkUpdate = () => {
|
checkUpdate = () => {
|
||||||
|
if (__DEV__) {
|
||||||
|
// 开发模式不支持热更新,跳过检查
|
||||||
|
return;
|
||||||
|
}
|
||||||
checkUpdate(appKey).then(info => {
|
checkUpdate(appKey).then(info => {
|
||||||
if (info.expired) {
|
if (info.expired) {
|
||||||
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
|
Alert.alert('提示', '您的应用版本已更新,请前往应用商店下载新的版本', [
|
||||||
@ -123,7 +127,7 @@ class MyProject extends Component {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
Alert.alert('提示', '更新失败.');
|
console.warn(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
render() {
|
render() {
|
||||||
|
44
lib/index.js
44
lib/index.js
@ -1,11 +1,7 @@
|
|||||||
/**
|
import { NativeAppEventEmitter, NativeModules } from 'react-native';
|
||||||
* Created by tdzl2003 on 4/4/16.
|
const { HotUpdate } = NativeModules;
|
||||||
*/
|
|
||||||
|
|
||||||
const HotUpdate = require('react-native').NativeModules.HotUpdate;
|
const host = 'https://update.reactnative.cn/api';
|
||||||
import {NativeAppEventEmitter} from 'react-native';
|
|
||||||
|
|
||||||
let host = 'https://update.reactnative.cn/api';
|
|
||||||
|
|
||||||
export const downloadRootDir = HotUpdate.downloadRootDir;
|
export const downloadRootDir = HotUpdate.downloadRootDir;
|
||||||
export const packageVersion = HotUpdate.packageVersion;
|
export const packageVersion = HotUpdate.packageVersion;
|
||||||
@ -36,11 +32,20 @@ There is available update:
|
|||||||
diffUrl: 'http://update-packages.reactnative.cn/hash',
|
diffUrl: 'http://update-packages.reactnative.cn/hash',
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function assertRelease() {
|
||||||
|
if (__DEV__) {
|
||||||
|
throw new Error('react-native-update can only run on RELEASE version.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function checkUpdate(APPKEY) {
|
export async function checkUpdate(APPKEY) {
|
||||||
|
assertRelease();
|
||||||
const resp = await fetch(`${host}/checkUpdate/${APPKEY}`, {
|
const resp = await fetch(`${host}/checkUpdate/${APPKEY}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@ -53,10 +58,11 @@ export async function checkUpdate(APPKEY) {
|
|||||||
throw new Error((await resp.json()).message);
|
throw new Error((await resp.json()).message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await resp.json();
|
return resp.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadUpdate(options) {
|
export async function downloadUpdate(options) {
|
||||||
|
assertRelease();
|
||||||
if (!options.update) {
|
if (!options.update) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -81,23 +87,21 @@ export async function downloadUpdate(options) {
|
|||||||
return options.hash;
|
return options.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function switchVersion(hash) {
|
export function switchVersion(hash) {
|
||||||
HotUpdate.reloadUpdate({hashName:hash});
|
assertRelease();
|
||||||
|
HotUpdate.reloadUpdate({ hashName: hash });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function switchVersionLater(hash) {
|
export function switchVersionLater(hash) {
|
||||||
HotUpdate.setNeedUpdate({hashName:hash});
|
assertRelease();
|
||||||
|
HotUpdate.setNeedUpdate({ hashName: hash });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function markSuccess() {
|
export function markSuccess() {
|
||||||
|
assertRelease();
|
||||||
HotUpdate.markSuccess();
|
HotUpdate.markSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NativeAppEventEmitter.addListener('RCTHotUpdateDownloadProgress', params => {});
|
||||||
|
|
||||||
NativeAppEventEmitter.addListener('RCTHotUpdateDownloadProgress',(params)=>{
|
NativeAppEventEmitter.addListener('RCTHotUpdateUnzipProgress', params => {});
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
NativeAppEventEmitter.addListener('RCTHotUpdateUnzipProgress',(params)=>{
|
|
||||||
|
|
||||||
})
|
|
||||||
|
Loading…
Reference in New Issue
Block a user