1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-10-31 21:33:12 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

bug fixed

This commit is contained in:
lvbingru
2016-04-06 09:42:34 +08:00
parent 7d8f1c9c10
commit 0b627ea540
9 changed files with 131 additions and 45 deletions

View File

@@ -119,6 +119,7 @@ android {
} }
dependencies { dependencies {
compile project(':react-native-update')
compile fileTree(dir: "libs", include: ["*.jar"]) compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1" compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:0.20.+" compile "com.facebook.react:react-native:0.20.+"

View File

@@ -1,3 +1,5 @@
rootProject.name = 'testHotUpdate' rootProject.name = 'testHotUpdate'
include ':app' include ':app'
include ':react-native-update'
project(':react-native-update').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-update/android')

View File

@@ -22,8 +22,9 @@
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
9F394D8C1C7C26C700C794C0 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F394D8B1C7C26C700C794C0 /* libz.tbd */; }; 9FED04301CB41E8F002487EC /* libbz2.1.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FED042F1CB41E8F002487EC /* libbz2.1.0.tbd */; };
9F394D8D1C7C2DA500C794C0 /* libRCTHotUpdate.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F394D4E1C7C25C400C794C0 /* libRCTHotUpdate.a */; }; 9FED04321CB41EC2002487EC /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FED04311CB41EC2002487EC /* libz.tbd */; };
D7FABDD031854D58B63B06A4 /* libRCTHotUpdate.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 855A53CDD4634785BD0AF87F /* libRCTHotUpdate.a */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@@ -104,9 +105,9 @@
remoteGlobalIDString = 58B5119B1A9E6C1200147676; remoteGlobalIDString = 58B5119B1A9E6C1200147676;
remoteInfo = RCTText; remoteInfo = RCTText;
}; };
9F394D4D1C7C25C400C794C0 /* PBXContainerItemProxy */ = { 9FED04251CB41D58002487EC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 9F394D471C7C25C400C794C0 /* RCTHotUpdate.xcodeproj */; containerPortal = 8295F7636DB14CAEA56E5A2B /* RCTHotUpdate.xcodeproj */;
proxyType = 2; proxyType = 2;
remoteGlobalIDString = 91C5EFFF1C76ECA90037E727; remoteGlobalIDString = 91C5EFFF1C76ECA90037E727;
remoteInfo = RCTHotUpdate; remoteInfo = RCTHotUpdate;
@@ -134,9 +135,11 @@
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = testHotUpdate/main.m; sourceTree = "<group>"; }; 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = testHotUpdate/main.m; sourceTree = "<group>"; };
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; }; 146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; }; 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
8295F7636DB14CAEA56E5A2B /* RCTHotUpdate.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RCTHotUpdate.xcodeproj; path = "../node_modules/react-native-update/ios/RCTHotUpdate.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; }; 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
9F394D471C7C25C400C794C0 /* RCTHotUpdate.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTHotUpdate.xcodeproj; path = "../node_modules/react-native-update/ios/RCTHotUpdate.xcodeproj"; sourceTree = "<group>"; }; 855A53CDD4634785BD0AF87F /* libRCTHotUpdate.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRCTHotUpdate.a; sourceTree = "<group>"; };
9F394D8B1C7C26C700C794C0 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 9FED042F1CB41E8F002487EC /* libbz2.1.0.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.1.0.tbd; path = usr/lib/libbz2.1.0.tbd; sourceTree = SDKROOT; };
9FED04311CB41EC2002487EC /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@@ -151,8 +154,8 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
9F394D8D1C7C2DA500C794C0 /* libRCTHotUpdate.a in Frameworks */, 9FED04321CB41EC2002487EC /* libz.tbd in Frameworks */,
9F394D8C1C7C26C700C794C0 /* libz.tbd in Frameworks */, 9FED04301CB41E8F002487EC /* libbz2.1.0.tbd in Frameworks */,
146834051AC3E58100842450 /* libReact.a in Frameworks */, 146834051AC3E58100842450 /* libReact.a in Frameworks */,
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */,
00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */, 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */,
@@ -163,6 +166,7 @@
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */, 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */,
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */, 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */, 139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
D7FABDD031854D58B63B06A4 /* libRCTHotUpdate.a in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@@ -275,7 +279,6 @@
832341AE1AAA6A7D00B99B32 /* Libraries */ = { 832341AE1AAA6A7D00B99B32 /* Libraries */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9F394D471C7C25C400C794C0 /* RCTHotUpdate.xcodeproj */,
146833FF1AC3E56700842450 /* React.xcodeproj */, 146833FF1AC3E56700842450 /* React.xcodeproj */,
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */, 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */,
00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */, 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */,
@@ -286,6 +289,7 @@
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */, 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */, 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */, 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
8295F7636DB14CAEA56E5A2B /* RCTHotUpdate.xcodeproj */,
); );
name = Libraries; name = Libraries;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -301,7 +305,8 @@
83CBB9F61A601CBA00E9B192 = { 83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9F394D8B1C7C26C700C794C0 /* libz.tbd */, 9FED04311CB41EC2002487EC /* libz.tbd */,
9FED042F1CB41E8F002487EC /* libbz2.1.0.tbd */,
13B07FAE1A68108700A75B9A /* testHotUpdate */, 13B07FAE1A68108700A75B9A /* testHotUpdate */,
832341AE1AAA6A7D00B99B32 /* Libraries */, 832341AE1AAA6A7D00B99B32 /* Libraries */,
00E356EF1AD99517003FC87E /* testHotUpdateTests */, 00E356EF1AD99517003FC87E /* testHotUpdateTests */,
@@ -320,10 +325,10 @@
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
9F394D481C7C25C400C794C0 /* Products */ = { 9FED04201CB41D58002487EC /* Products */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9F394D4E1C7C25C400C794C0 /* libRCTHotUpdate.a */, 9FED04261CB41D58002487EC /* libRCTHotUpdate.a */,
); );
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -373,7 +378,7 @@
83CBB9F71A601CBA00E9B192 /* Project object */ = { 83CBB9F71A601CBA00E9B192 /* Project object */ = {
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastUpgradeCheck = 0610; LastUpgradeCheck = 610;
ORGANIZATIONNAME = Facebook; ORGANIZATIONNAME = Facebook;
TargetAttributes = { TargetAttributes = {
00E356ED1AD99517003FC87E = { 00E356ED1AD99517003FC87E = {
@@ -403,8 +408,8 @@
ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */; ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */;
}, },
{ {
ProductGroup = 9F394D481C7C25C400C794C0 /* Products */; ProductGroup = 9FED04201CB41D58002487EC /* Products */;
ProjectRef = 9F394D471C7C25C400C794C0 /* RCTHotUpdate.xcodeproj */; ProjectRef = 8295F7636DB14CAEA56E5A2B /* RCTHotUpdate.xcodeproj */;
}, },
{ {
ProductGroup = 00C302BC1ABCB91800DB3ED1 /* Products */; ProductGroup = 00C302BC1ABCB91800DB3ED1 /* Products */;
@@ -518,11 +523,11 @@
remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */; remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR; sourceTree = BUILT_PRODUCTS_DIR;
}; };
9F394D4E1C7C25C400C794C0 /* libRCTHotUpdate.a */ = { 9FED04261CB41D58002487EC /* libRCTHotUpdate.a */ = {
isa = PBXReferenceProxy; isa = PBXReferenceProxy;
fileType = archive.ar; fileType = archive.ar;
path = libRCTHotUpdate.a; path = libRCTHotUpdate.a;
remoteRef = 9F394D4D1C7C25C400C794C0 /* PBXContainerItemProxy */; remoteRef = 9FED04251CB41D58002487EC /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR; sourceTree = BUILT_PRODUCTS_DIR;
}; };
/* End PBXReferenceProxy section */ /* End PBXReferenceProxy section */
@@ -619,6 +624,10 @@
INFOPLIST_FILE = testHotUpdateTests/Info.plist; INFOPLIST_FILE = testHotUpdateTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.2; IPHONEOS_DEPLOYMENT_TARGET = 8.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/testHotUpdate.app/testHotUpdate"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/testHotUpdate.app/testHotUpdate";
}; };
@@ -636,6 +645,10 @@
INFOPLIST_FILE = testHotUpdateTests/Info.plist; INFOPLIST_FILE = testHotUpdateTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.2; IPHONEOS_DEPLOYMENT_TARGET = 8.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/testHotUpdate.app/testHotUpdate"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/testHotUpdate.app/testHotUpdate";
}; };
@@ -650,12 +663,14 @@
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native/React/**", "$(SRCROOT)/../node_modules/react-native/React/**",
"$(SRCROOT)/../node_modules/react-native-update/ios/RCTHotUpdate", "$(SRCROOT)/../node_modules/react-native-update/ios/RCTHotUpdate/**",
); );
INFOPLIST_FILE = testHotUpdate/Info.plist; INFOPLIST_FILE = testHotUpdate/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = "-ObjC"; OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = com.tdzl.testHotUpdate;
PRODUCT_NAME = testHotUpdate; PRODUCT_NAME = testHotUpdate;
PROVISIONING_PROFILE = "";
}; };
name = Debug; name = Debug;
}; };
@@ -663,16 +678,19 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Distribution: Hangzhou Erica Network Technology Co., Ltd. (4W77ET7ZNV)";
HEADER_SEARCH_PATHS = ( HEADER_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native/React/**", "$(SRCROOT)/../node_modules/react-native/React/**",
"$(SRCROOT)/../node_modules/react-native-update/ios/RCTHotUpdate", "$(SRCROOT)/../node_modules/react-native-update/ios/RCTHotUpdate/**",
); );
INFOPLIST_FILE = testHotUpdate/Info.plist; INFOPLIST_FILE = testHotUpdate/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = "-ObjC"; OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = com.tdzl.testHotUpdate;
PRODUCT_NAME = testHotUpdate; PRODUCT_NAME = testHotUpdate;
PROVISIONING_PROFILE = "e3e045ab-62fc-4c86-bcb3-4d78583e3fe2";
}; };
name = Release; name = Release;
}; };
@@ -714,6 +732,7 @@
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native/React/**", "$(SRCROOT)/../node_modules/react-native/React/**",
"$(SRCROOT)/../node_modules/react-native-update/ios/RCTHotUpdate/**",
); );
IPHONEOS_DEPLOYMENT_TARGET = 7.0; IPHONEOS_DEPLOYMENT_TARGET = 7.0;
MTL_ENABLE_DEBUG_INFO = YES; MTL_ENABLE_DEBUG_INFO = YES;
@@ -754,6 +773,7 @@
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native/React/**", "$(SRCROOT)/../node_modules/react-native/React/**",
"$(SRCROOT)/../node_modules/react-native-update/ios/RCTHotUpdate/**",
); );
IPHONEOS_DEPLOYMENT_TARGET = 7.0; IPHONEOS_DEPLOYMENT_TARGET = 7.0;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;

Binary file not shown.

After

Width:  |  Height:  |  Size: 696 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -7,39 +7,91 @@ import React, {
AppRegistry, AppRegistry,
Component, Component,
StyleSheet, StyleSheet,
Platform,
Text, Text,
View, View,
Alert,
TouchableOpacity, TouchableOpacity,
Linking,
Image,
} from 'react-native'; } 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() { render() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Text style={styles.welcome}> <Text style={styles.welcome}>
Welcome to React Native! 欢迎使用热更新服务
</Text> </Text>
<Image
resizeMode = {'contain'}
source = {require('./assets/shoucang.png')}
style = {styles.image}
/>
<Text style={styles.instructions}> <Text style={styles.instructions}>
To get started, edit index.ios.js 这是版本一 {'\n'}
当前包版本号: {packageVersion}{'\n'}
当前版本Hash: {currentVersion||'(空)'}{'\n'}
</Text> </Text>
<TouchableOpacity onPress={ <TouchableOpacity onPress={this.checkUpdate}>
()=>{
downloadFile({updateUrl:'http://7xjhby.com2.z0.glb.qiniucdn.com/ios1.ppk', hashName:'test'})
}
}>
<Text style={styles.instructions}> <Text style={styles.instructions}>
Press To DownloadFile 点击这里检查更新
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={
()=>{
reloadUpdate({hashName:'test'})
}
}>
<Text style={styles.instructions}>
Press To Reload
</Text> </Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
@@ -64,6 +116,8 @@ const styles = StyleSheet.create({
color: '#333333', color: '#333333',
marginBottom: 5, marginBottom: 5,
}, },
image : {
},
}); });
AppRegistry.registerComponent('testHotUpdate', () => testHotUpdate); AppRegistry.registerComponent('testHotUpdate', () => MyProject);

View File

@@ -20,6 +20,7 @@ static NSString *const paramLastVersion = @"lastVersion";
static NSString *const paramCurrentVersion = @"currentVersion"; static NSString *const paramCurrentVersion = @"currentVersion";
static NSString *const paramIsFirstTime = @"isFirstTime"; static NSString *const paramIsFirstTime = @"isFirstTime";
static NSString *const paramIsFirstLoadOk = @"isFirstLoadOK"; static NSString *const paramIsFirstLoadOk = @"isFirstLoadOK";
static NSString *const keyFirstLoadLoadMarked = @"REACTNATIVECN_HOTUPDATE_FIRSTLOADMARKED_KEY";
static NSString *const keyRolledBackMarked = @"REACTNATIVECN_HOTUPDATE_ROLLEDBACKMARKED_KEY"; static NSString *const keyRolledBackMarked = @"REACTNATIVECN_HOTUPDATE_ROLLEDBACKMARKED_KEY";
static NSString *const KeyPackageUpdatedMarked = @"REACTNATIVECN_HOTUPDATE_ISPACKAGEUPDATEDMARKED_KEY"; static NSString *const KeyPackageUpdatedMarked = @"REACTNATIVECN_HOTUPDATE_ISPACKAGEUPDATEDMARKED_KEY";
@@ -40,6 +41,7 @@ static NSString * const ERROR_FILE_OPERATION = @"file operation error";
// event def // event def
static NSString * const EVENT_PROGRESS_DOWNLOAD = @"RCTHotUpdateDownloadProgress"; static NSString * const EVENT_PROGRESS_DOWNLOAD = @"RCTHotUpdateDownloadProgress";
static NSString * const EVENT_PROGRESS_UNZIP = @"RCTHotUpdateUnzipProgress"; static NSString * const EVENT_PROGRESS_UNZIP = @"RCTHotUpdateUnzipProgress";
static NSString * const PARAM_PROGRESS_HASHNAME = @"hashname";
static NSString * const PARAM_PROGRESS_RECEIVED = @"received"; static NSString * const PARAM_PROGRESS_RECEIVED = @"received";
static NSString * const PARAM_PROGRESS_TOTAL = @"total"; static NSString * const PARAM_PROGRESS_TOTAL = @"total";
@@ -103,6 +105,13 @@ RCT_EXPORT_MODULE(RCTHotUpdate);
[defaults synchronize]; [defaults synchronize];
// ...need clear files later // ...need clear files later
} }
else if (isFirstTime){
NSMutableDictionary *newInfo = [updateInfo mutableCopy];
newInfo[paramIsFirstTime] = @(NO);
[defaults setObject:newInfo forKey:keyUpdateInfo];
[defaults setObject:@(YES) forKey:keyFirstLoadLoadMarked];
[defaults synchronize];
}
if (loadVersioin.length) { if (loadVersioin.length) {
NSString *downloadDir = [RCTHotUpdate downloadDir]; NSString *downloadDir = [RCTHotUpdate downloadDir];
@@ -127,15 +136,13 @@ RCT_EXPORT_MODULE(RCTHotUpdate);
ret[@"downloadRootDir"] = [RCTHotUpdate downloadDir]; ret[@"downloadRootDir"] = [RCTHotUpdate downloadDir];
ret[@"packageVersion"] = [RCTHotUpdate packageVersion]; ret[@"packageVersion"] = [RCTHotUpdate packageVersion];
ret[@"isRolledBack"] = [defaults objectForKey:keyRolledBackMarked]; ret[@"isRolledBack"] = [defaults objectForKey:keyRolledBackMarked];
ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadLoadMarked];
NSDictionary *updateInfo = [defaults dictionaryForKey:keyUpdateInfo]; NSDictionary *updateInfo = [defaults dictionaryForKey:keyUpdateInfo];
ret[@"currentVersion"] = [updateInfo objectForKey:paramCurrentVersion]; ret[@"currentVersion"] = [updateInfo objectForKey:paramCurrentVersion];
ret[@"isFirstTime"] = [updateInfo objectForKey:paramIsFirstTime];
// clear isFirstTime // clear isFirstTime
if (updateInfo) { if ([[defaults objectForKey:keyFirstLoadLoadMarked] boolValue]) {
NSMutableDictionary *newInfo = [updateInfo mutableCopy]; [defaults setObject:nil forKey:keyFirstLoadLoadMarked];
newInfo[paramIsFirstTime] = @(NO);
[defaults setObject:newInfo forKey:keyUpdateInfo];
} }
// clear rolledbackmark // clear rolledbackmark
@@ -285,6 +292,7 @@ RCT_EXPORT_METHOD(markSuccuss)
[RCTHotUpdateDownloader download:updateUrl savePath:zipFilePath progressHandler:^(long long receivedBytes, long long totalBytes) { [RCTHotUpdateDownloader download:updateUrl savePath:zipFilePath progressHandler:^(long long receivedBytes, long long totalBytes) {
[self.bridge.eventDispatcher sendAppEventWithName:EVENT_PROGRESS_DOWNLOAD [self.bridge.eventDispatcher sendAppEventWithName:EVENT_PROGRESS_DOWNLOAD
body:@{ body:@{
PARAM_PROGRESS_HASHNAME:hashName,
PARAM_PROGRESS_RECEIVED:[NSNumber numberWithLongLong:receivedBytes], PARAM_PROGRESS_RECEIVED:[NSNumber numberWithLongLong:receivedBytes],
PARAM_PROGRESS_TOTAL:[NSNumber numberWithLongLong:totalBytes] PARAM_PROGRESS_TOTAL:[NSNumber numberWithLongLong:totalBytes]
}]; }];
@@ -298,6 +306,7 @@ RCT_EXPORT_METHOD(markSuccuss)
[_fileManager unzipFileAtPath:zipFilePath toDestination:unzipFilePath progressHandler:^(NSString *entry,long entryNumber, long total) { [_fileManager unzipFileAtPath:zipFilePath toDestination:unzipFilePath progressHandler:^(NSString *entry,long entryNumber, long total) {
[self.bridge.eventDispatcher sendAppEventWithName:EVENT_PROGRESS_UNZIP [self.bridge.eventDispatcher sendAppEventWithName:EVENT_PROGRESS_UNZIP
body:@{ body:@{
PARAM_PROGRESS_HASHNAME:hashName,
PARAM_PROGRESS_RECEIVED:[NSNumber numberWithLong:entryNumber], PARAM_PROGRESS_RECEIVED:[NSNumber numberWithLong:entryNumber],
PARAM_PROGRESS_TOTAL:[NSNumber numberWithLong:total] PARAM_PROGRESS_TOTAL:[NSNumber numberWithLong:total]
}]; }];

View File

@@ -103,7 +103,7 @@ completionHandler:(void (^)(NSError *error))completionHandler
NSString *toPath = [toDir stringByAppendingPathComponent:to]; NSString *toPath = [toDir stringByAppendingPathComponent:to];
NSError *error = nil; NSError *error = nil;
[[NSFileManager defaultManager] moveItemAtPath:fromPath toPath:toPath error:&error]; [[NSFileManager defaultManager] copyItemAtPath:fromPath toPath:toPath error:&error];
if (error) { if (error) {
if (completionHandler) { if (completionHandler) {
completionHandler(error); completionHandler(error);