From 0b627ea540d5b4047c89af57d375d90c29c66ab7 Mon Sep 17 00:00:00 2001 From: lvbingru Date: Wed, 6 Apr 2016 09:42:34 +0800 Subject: [PATCH] bug fixed --- .../testHotUpdate/android/app/build.gradle | 1 + Example/testHotUpdate/android/settings.gradle | 2 + .../testHotUpdate.xcodeproj/project.pbxproj | 58 +++++++---- Example/testHotUpdate/js/assets/shezhi.png | Bin 0 -> 696 bytes Example/testHotUpdate/js/assets/shezhi@2x.png | Bin 0 -> 1257 bytes Example/testHotUpdate/js/assets/shezhi@3x.png | Bin 0 -> 1859 bytes Example/testHotUpdate/js/index.js | 94 ++++++++++++++---- ios/RCTHotUpdate/RCTHotUpdate.m | 19 +++- ios/RCTHotUpdate/RCTHotUpdateManager.m | 2 +- 9 files changed, 131 insertions(+), 45 deletions(-) create mode 100644 Example/testHotUpdate/js/assets/shezhi.png create mode 100644 Example/testHotUpdate/js/assets/shezhi@2x.png create mode 100644 Example/testHotUpdate/js/assets/shezhi@3x.png diff --git a/Example/testHotUpdate/android/app/build.gradle b/Example/testHotUpdate/android/app/build.gradle index 2ccef9c..ed5f4f9 100644 --- a/Example/testHotUpdate/android/app/build.gradle +++ b/Example/testHotUpdate/android/app/build.gradle @@ -119,6 +119,7 @@ android { } dependencies { + compile project(':react-native-update') compile fileTree(dir: "libs", include: ["*.jar"]) compile "com.android.support:appcompat-v7:23.0.1" compile "com.facebook.react:react-native:0.20.+" diff --git a/Example/testHotUpdate/android/settings.gradle b/Example/testHotUpdate/android/settings.gradle index b65321c..d088d17 100644 --- a/Example/testHotUpdate/android/settings.gradle +++ b/Example/testHotUpdate/android/settings.gradle @@ -1,3 +1,5 @@ rootProject.name = 'testHotUpdate' include ':app' +include ':react-native-update' +project(':react-native-update').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-update/android') diff --git a/Example/testHotUpdate/ios/testHotUpdate.xcodeproj/project.pbxproj b/Example/testHotUpdate/ios/testHotUpdate.xcodeproj/project.pbxproj index c6b9d75..e64f4cd 100644 --- a/Example/testHotUpdate/ios/testHotUpdate.xcodeproj/project.pbxproj +++ b/Example/testHotUpdate/ios/testHotUpdate.xcodeproj/project.pbxproj @@ -22,8 +22,9 @@ 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; - 9F394D8C1C7C26C700C794C0 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F394D8B1C7C26C700C794C0 /* libz.tbd */; }; - 9F394D8D1C7C2DA500C794C0 /* libRCTHotUpdate.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F394D4E1C7C25C400C794C0 /* libRCTHotUpdate.a */; }; + 9FED04301CB41E8F002487EC /* libbz2.1.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FED042F1CB41E8F002487EC /* libbz2.1.0.tbd */; }; + 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 */ /* Begin PBXContainerItemProxy section */ @@ -104,9 +105,9 @@ remoteGlobalIDString = 58B5119B1A9E6C1200147676; remoteInfo = RCTText; }; - 9F394D4D1C7C25C400C794C0 /* PBXContainerItemProxy */ = { + 9FED04251CB41D58002487EC /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; - containerPortal = 9F394D471C7C25C400C794C0 /* RCTHotUpdate.xcodeproj */; + containerPortal = 8295F7636DB14CAEA56E5A2B /* RCTHotUpdate.xcodeproj */; proxyType = 2; remoteGlobalIDString = 91C5EFFF1C76ECA90037E727; 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 = ""; }; 146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = ""; }; 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = ""; }; + 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 = ""; }; 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = ""; }; - 9F394D471C7C25C400C794C0 /* RCTHotUpdate.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTHotUpdate.xcodeproj; path = "../node_modules/react-native-update/ios/RCTHotUpdate.xcodeproj"; sourceTree = ""; }; - 9F394D8B1C7C26C700C794C0 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; + 855A53CDD4634785BD0AF87F /* libRCTHotUpdate.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRCTHotUpdate.a; sourceTree = ""; }; + 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 */ /* Begin PBXFrameworksBuildPhase section */ @@ -151,8 +154,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9F394D8D1C7C2DA500C794C0 /* libRCTHotUpdate.a in Frameworks */, - 9F394D8C1C7C26C700C794C0 /* libz.tbd in Frameworks */, + 9FED04321CB41EC2002487EC /* libz.tbd in Frameworks */, + 9FED04301CB41E8F002487EC /* libbz2.1.0.tbd in Frameworks */, 146834051AC3E58100842450 /* libReact.a in Frameworks */, 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */, @@ -163,6 +166,7 @@ 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */, 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */, 139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */, + D7FABDD031854D58B63B06A4 /* libRCTHotUpdate.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -275,7 +279,6 @@ 832341AE1AAA6A7D00B99B32 /* Libraries */ = { isa = PBXGroup; children = ( - 9F394D471C7C25C400C794C0 /* RCTHotUpdate.xcodeproj */, 146833FF1AC3E56700842450 /* React.xcodeproj */, 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */, 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */, @@ -286,6 +289,7 @@ 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */, 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */, 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */, + 8295F7636DB14CAEA56E5A2B /* RCTHotUpdate.xcodeproj */, ); name = Libraries; sourceTree = ""; @@ -301,7 +305,8 @@ 83CBB9F61A601CBA00E9B192 = { isa = PBXGroup; children = ( - 9F394D8B1C7C26C700C794C0 /* libz.tbd */, + 9FED04311CB41EC2002487EC /* libz.tbd */, + 9FED042F1CB41E8F002487EC /* libbz2.1.0.tbd */, 13B07FAE1A68108700A75B9A /* testHotUpdate */, 832341AE1AAA6A7D00B99B32 /* Libraries */, 00E356EF1AD99517003FC87E /* testHotUpdateTests */, @@ -320,10 +325,10 @@ name = Products; sourceTree = ""; }; - 9F394D481C7C25C400C794C0 /* Products */ = { + 9FED04201CB41D58002487EC /* Products */ = { isa = PBXGroup; children = ( - 9F394D4E1C7C25C400C794C0 /* libRCTHotUpdate.a */, + 9FED04261CB41D58002487EC /* libRCTHotUpdate.a */, ); name = Products; sourceTree = ""; @@ -373,7 +378,7 @@ 83CBB9F71A601CBA00E9B192 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0610; + LastUpgradeCheck = 610; ORGANIZATIONNAME = Facebook; TargetAttributes = { 00E356ED1AD99517003FC87E = { @@ -403,8 +408,8 @@ ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */; }, { - ProductGroup = 9F394D481C7C25C400C794C0 /* Products */; - ProjectRef = 9F394D471C7C25C400C794C0 /* RCTHotUpdate.xcodeproj */; + ProductGroup = 9FED04201CB41D58002487EC /* Products */; + ProjectRef = 8295F7636DB14CAEA56E5A2B /* RCTHotUpdate.xcodeproj */; }, { ProductGroup = 00C302BC1ABCB91800DB3ED1 /* Products */; @@ -518,11 +523,11 @@ remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 9F394D4E1C7C25C400C794C0 /* libRCTHotUpdate.a */ = { + 9FED04261CB41D58002487EC /* libRCTHotUpdate.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; path = libRCTHotUpdate.a; - remoteRef = 9F394D4D1C7C25C400C794C0 /* PBXContainerItemProxy */; + remoteRef = 9FED04251CB41D58002487EC /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXReferenceProxy section */ @@ -619,6 +624,10 @@ INFOPLIST_FILE = testHotUpdateTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/$(TARGET_NAME)\"", + ); PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/testHotUpdate.app/testHotUpdate"; }; @@ -636,6 +645,10 @@ INFOPLIST_FILE = testHotUpdateTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/$(TARGET_NAME)\"", + ); PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/testHotUpdate.app/testHotUpdate"; }; @@ -650,12 +663,14 @@ "$(inherited)", /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, "$(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; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = com.tdzl.testHotUpdate; PRODUCT_NAME = testHotUpdate; + PROVISIONING_PROFILE = ""; }; name = Debug; }; @@ -663,16 +678,19 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Distribution: Hangzhou Erica Network Technology Co., Ltd. (4W77ET7ZNV)"; HEADER_SEARCH_PATHS = ( "$(inherited)", /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, "$(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; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = com.tdzl.testHotUpdate; PRODUCT_NAME = testHotUpdate; + PROVISIONING_PROFILE = "e3e045ab-62fc-4c86-bcb3-4d78583e3fe2"; }; name = Release; }; @@ -714,6 +732,7 @@ "$(inherited)", /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, "$(SRCROOT)/../node_modules/react-native/React/**", + "$(SRCROOT)/../node_modules/react-native-update/ios/RCTHotUpdate/**", ); IPHONEOS_DEPLOYMENT_TARGET = 7.0; MTL_ENABLE_DEBUG_INFO = YES; @@ -754,6 +773,7 @@ "$(inherited)", /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, "$(SRCROOT)/../node_modules/react-native/React/**", + "$(SRCROOT)/../node_modules/react-native-update/ios/RCTHotUpdate/**", ); IPHONEOS_DEPLOYMENT_TARGET = 7.0; MTL_ENABLE_DEBUG_INFO = NO; diff --git a/Example/testHotUpdate/js/assets/shezhi.png b/Example/testHotUpdate/js/assets/shezhi.png new file mode 100644 index 0000000000000000000000000000000000000000..ca6172005a7676c7571e58bba8f9f8e011777672 GIT binary patch literal 696 zcmV;p0!RIcP)#72NG-IZRf5l77*9SC?Wk17J9>xK4j#R@(r4i^4G;=mR73YQdY zD|U_y0)br!SSgm`%;ZYk_klj=0-)S0CAruQoSr%=ItnnIr3gj6n@V>^42KAn8^LIO z2Dx+guWN}qhQ)`oPdUDnuCV8z$5Pk#8Q!TZTazv+FGJz4uzjKqYT7VKwx)f#nB)7g zi&D>Np@#@%BZA!?!J}!p;tPnJ!Fx2=3VW>vz?o3twTCubgDw(HN#IIZA*LC9#ojT_ zaP&C^ovMR1@#>dx-djDOupP4DGX~yK9~GQI^`FWK9$Xno(DDJi-iebPHH>AoMweTp z-dmp%e!%KiNO|7VB5bI;6Y5I{O%NIt48#{oh9J3!^=Rx0qQ8p$%-O3nT}MO zk%C)k)<;e;R?t0N8c@91MvF}Yoo%nP2%JCDq-_3j2BiQT(3BYlrquGvX!omhQPmwTfX zb$K0l97yaZ)116OO)aunqI-AXy?~;g1TcH=kG=xz>7T@0W;b%KdY6L<#dOpIJ&lHD e?r+O40R{k!_av3-7wr=O0000=P)vSSV+3-k=1R?i17v_7S&vpINb{xwC_oGKQ(Ay}6r!=#7AWY*vE?HOg2L>M zCV&Ey<3T5mWlz>X@ZSUVa}NSbts)Wtc#c~9Dg@D^pjXVZkxvLEKrT5b6@Uk-v;p7~ z1W1A3stL+CRr3yoIi3?M@Qnj_kA6_&@0I5)0H52Ajx>XLX6~)ljbFn8oI@=^lj;!Q zYNsYR^*K7D7(5L1Kdk`Uf}%0>Jnx8T0S>w$fNU^a+SXXAXGL`cS-{TE3@8j(9Rlfbz+SF*#cZLEosuN=JsOFQ$ypa2=CI zGda~cIJ2fuDFna5w3s?%h8N#00bV;JJlo;g5bM-L+EJJm*n2=X7{0my4f)0#fk~}U zW9?y%cY_a~J_Gk2LP1-a{}D<33u)Sn{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Example/testHotUpdate/js/index.js index 7f57cde..209a4d0 100644 --- a/Example/testHotUpdate/js/index.js +++ b/Example/testHotUpdate/js/index.js @@ -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 ( - Welcome to React Native! + 欢迎使用热更新服务 + - To get started, edit index.ios.js + 这是版本一 {'\n'} + 当前包版本号: {packageVersion}{'\n'} + 当前版本Hash: {currentVersion||'(空)'}{'\n'} - { - downloadFile({updateUrl:'http://7xjhby.com2.z0.glb.qiniucdn.com/ios1.ppk', hashName:'test'}) - } - }> + - Press To DownloadFile - - - { - reloadUpdate({hashName:'test'}) - } - }> - - Press To Reload + 点击这里检查更新 @@ -64,6 +116,8 @@ const styles = StyleSheet.create({ color: '#333333', marginBottom: 5, }, + image : { + }, }); -AppRegistry.registerComponent('testHotUpdate', () => testHotUpdate); +AppRegistry.registerComponent('testHotUpdate', () => MyProject); diff --git a/ios/RCTHotUpdate/RCTHotUpdate.m b/ios/RCTHotUpdate/RCTHotUpdate.m index 88991c1..539daa5 100644 --- a/ios/RCTHotUpdate/RCTHotUpdate.m +++ b/ios/RCTHotUpdate/RCTHotUpdate.m @@ -20,6 +20,7 @@ static NSString *const paramLastVersion = @"lastVersion"; static NSString *const paramCurrentVersion = @"currentVersion"; static NSString *const paramIsFirstTime = @"isFirstTime"; static NSString *const paramIsFirstLoadOk = @"isFirstLoadOK"; +static NSString *const keyFirstLoadLoadMarked = @"REACTNATIVECN_HOTUPDATE_FIRSTLOADMARKED_KEY"; static NSString *const keyRolledBackMarked = @"REACTNATIVECN_HOTUPDATE_ROLLEDBACKMARKED_KEY"; static NSString *const KeyPackageUpdatedMarked = @"REACTNATIVECN_HOTUPDATE_ISPACKAGEUPDATEDMARKED_KEY"; @@ -40,6 +41,7 @@ static NSString * const ERROR_FILE_OPERATION = @"file operation error"; // event def static NSString * const EVENT_PROGRESS_DOWNLOAD = @"RCTHotUpdateDownloadProgress"; 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_TOTAL = @"total"; @@ -103,6 +105,13 @@ RCT_EXPORT_MODULE(RCTHotUpdate); [defaults synchronize]; // ...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) { NSString *downloadDir = [RCTHotUpdate downloadDir]; @@ -127,15 +136,13 @@ RCT_EXPORT_MODULE(RCTHotUpdate); ret[@"downloadRootDir"] = [RCTHotUpdate downloadDir]; ret[@"packageVersion"] = [RCTHotUpdate packageVersion]; ret[@"isRolledBack"] = [defaults objectForKey:keyRolledBackMarked]; + ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadLoadMarked]; NSDictionary *updateInfo = [defaults dictionaryForKey:keyUpdateInfo]; ret[@"currentVersion"] = [updateInfo objectForKey:paramCurrentVersion]; - ret[@"isFirstTime"] = [updateInfo objectForKey:paramIsFirstTime]; // clear isFirstTime - if (updateInfo) { - NSMutableDictionary *newInfo = [updateInfo mutableCopy]; - newInfo[paramIsFirstTime] = @(NO); - [defaults setObject:newInfo forKey:keyUpdateInfo]; + if ([[defaults objectForKey:keyFirstLoadLoadMarked] boolValue]) { + [defaults setObject:nil forKey:keyFirstLoadLoadMarked]; } // clear rolledbackmark @@ -285,6 +292,7 @@ RCT_EXPORT_METHOD(markSuccuss) [RCTHotUpdateDownloader download:updateUrl savePath:zipFilePath progressHandler:^(long long receivedBytes, long long totalBytes) { [self.bridge.eventDispatcher sendAppEventWithName:EVENT_PROGRESS_DOWNLOAD body:@{ + PARAM_PROGRESS_HASHNAME:hashName, PARAM_PROGRESS_RECEIVED:[NSNumber numberWithLongLong:receivedBytes], 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) { [self.bridge.eventDispatcher sendAppEventWithName:EVENT_PROGRESS_UNZIP body:@{ + PARAM_PROGRESS_HASHNAME:hashName, PARAM_PROGRESS_RECEIVED:[NSNumber numberWithLong:entryNumber], PARAM_PROGRESS_TOTAL:[NSNumber numberWithLong:total] }]; diff --git a/ios/RCTHotUpdate/RCTHotUpdateManager.m b/ios/RCTHotUpdate/RCTHotUpdateManager.m index d4d8392..a89a04f 100644 --- a/ios/RCTHotUpdate/RCTHotUpdateManager.m +++ b/ios/RCTHotUpdate/RCTHotUpdateManager.m @@ -103,7 +103,7 @@ completionHandler:(void (^)(NSError *error))completionHandler NSString *toPath = [toDir stringByAppendingPathComponent:to]; NSError *error = nil; - [[NSFileManager defaultManager] moveItemAtPath:fromPath toPath:toPath error:&error]; + [[NSFileManager defaultManager] copyItemAtPath:fromPath toPath:toPath error:&error]; if (error) { if (completionHandler) { completionHandler(error);