From 6a0a5b2d49e3622f96cd7a69d86a0211d42bdbd3 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Fri, 27 Jun 2025 23:23:59 +0800 Subject: [PATCH] fix ios reload --- Example/testHotUpdate/bun.lock | 16 ++++---- .../ios/AwesomeProject/AppDelegate.mm | 2 + Example/testHotUpdate/ios/Podfile.lock | 28 ++++++------- Example/testHotUpdate/package.json | 8 ++-- Example/testHotUpdate/update.json | 4 +- ios/RCTPushy/RCTPushy.mm | 40 +++++++++---------- package.json | 2 +- 7 files changed, 51 insertions(+), 49 deletions(-) diff --git a/Example/testHotUpdate/bun.lock b/Example/testHotUpdate/bun.lock index e968093..19e00ae 100644 --- a/Example/testHotUpdate/bun.lock +++ b/Example/testHotUpdate/bun.lock @@ -4,15 +4,15 @@ "": { "name": "testHotUpdate", "dependencies": { - "form-data": "^4.0.2", + "form-data": "^4.0.3", "patch-package": "^8.0.0", "react": "19.0.0", "react-native": "0.79.2", - "react-native-camera-kit": "^15.0.1", + "react-native-camera-kit": "^15.1.0", "react-native-paper": "^5.14.5", - "react-native-safe-area-context": "^5.4.1", + "react-native-safe-area-context": "^5.5.0", "react-native-svg": "^15.12.0", - "react-native-update": "^10.29.0", + "react-native-update": "^10.29.4", "react-native-vector-icons": "^10.2.0", }, "devDependencies": { @@ -886,7 +886,7 @@ "for-each": ["for-each@0.3.5", "", { "dependencies": { "is-callable": "^1.2.7" } }, "sha512-dKx12eRCVIzqCxFGplyFKJMPvLEWgmNtUrpTiJIR5u97zEhRG8ySrtboPHZXx7daLxQVrl643cTzbab2tkQjxg=="], - "form-data": ["form-data@4.0.2", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "mime-types": "^2.1.12" } }, "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w=="], + "form-data": ["form-data@4.0.3", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.2", "mime-types": "^2.1.12" } }, "sha512-qsITQPfmvMOSAdeyZ+12I1c+CKSstAFAwu+97zrnWAbIr5u8wfsExUzCesVLC8NgHuRUqNN4Zy6UPWUTRGslcA=="], "fresh": ["fresh@0.5.2", "", {}, "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q=="], @@ -1412,15 +1412,15 @@ "react-native": ["react-native@0.79.2", "", { "dependencies": { "@jest/create-cache-key-function": "^29.7.0", "@react-native/assets-registry": "0.79.2", "@react-native/codegen": "0.79.2", "@react-native/community-cli-plugin": "0.79.2", "@react-native/gradle-plugin": "0.79.2", "@react-native/js-polyfills": "0.79.2", "@react-native/normalize-colors": "0.79.2", "@react-native/virtualized-lists": "0.79.2", "abort-controller": "^3.0.0", "anser": "^1.4.9", "ansi-regex": "^5.0.0", "babel-jest": "^29.7.0", "babel-plugin-syntax-hermes-parser": "0.25.1", "base64-js": "^1.5.1", "chalk": "^4.0.0", "commander": "^12.0.0", "event-target-shim": "^5.0.1", "flow-enums-runtime": "^0.0.6", "glob": "^7.1.1", "invariant": "^2.2.4", "jest-environment-node": "^29.7.0", "memoize-one": "^5.0.0", "metro-runtime": "^0.82.0", "metro-source-map": "^0.82.0", "nullthrows": "^1.1.1", "pretty-format": "^29.7.0", "promise": "^8.3.0", "react-devtools-core": "^6.1.1", "react-refresh": "^0.14.0", "regenerator-runtime": "^0.13.2", "scheduler": "0.25.0", "semver": "^7.1.3", "stacktrace-parser": "^0.1.10", "whatwg-fetch": "^3.0.0", "ws": "^6.2.3", "yargs": "^17.6.2" }, "peerDependencies": { "@types/react": "^19.0.0", "react": "^19.0.0" }, "optionalPeers": ["@types/react"], "bin": { "react-native": "cli.js" } }, "sha512-AnGzb56JvU5YCL7cAwg10+ewDquzvmgrMddiBM0GAWLwQM/6DJfGd2ZKrMuKKehHerpDDZgG+EY64gk3x3dEkw=="], - "react-native-camera-kit": ["react-native-camera-kit@15.0.1", "", { "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-JAa/2m73vKRp9oJ6ynYDr2KIIbglUbXYmDmsUrxLdk820eMGfxlb2HukqmVrkwt9KgX5vlBWoDHys3dhmrqa/w=="], + "react-native-camera-kit": ["react-native-camera-kit@15.1.0", "", { "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-4gPOJAoWAj9WaiNxPgKFYa/+M79O/Ggvc271SGgH5TmetmtinctJFm2zxeg+bAxVS9TDIYcF3ojRD98n88+VEw=="], "react-native-paper": ["react-native-paper@5.14.5", "", { "dependencies": { "@callstack/react-theme-provider": "^3.0.9", "color": "^3.1.2", "use-latest-callback": "^0.2.3" }, "peerDependencies": { "react": "*", "react-native": "*", "react-native-safe-area-context": "*" } }, "sha512-eaIH5bUQjJ/mYm4AkI6caaiyc7BcHDwX6CqNDi6RIxfxfWxROsHpll1oBuwn/cFvknvA8uEAkqLk/vzVihI3AQ=="], - "react-native-safe-area-context": ["react-native-safe-area-context@5.4.1", "", { "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-x+g3NblZ9jof8y+XkVvaGlpMrSlixhrJJ33BRzhTAKUKctQVecO1heSXmzxc5UdjvGYBKS6kPZVUw2b8NxHcPg=="], + "react-native-safe-area-context": ["react-native-safe-area-context@5.5.0", "", { "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-BQcSvVEJj3T4zBQH9YrnlfcLGHiVOsmeiE10PSBsmI/xyzULSZdJISFOH0HLcLU7/nePC+HsaaVzIsEa1CVBYw=="], "react-native-svg": ["react-native-svg@15.12.0", "", { "dependencies": { "css-select": "^5.1.0", "css-tree": "^1.1.3", "warn-once": "0.1.1" }, "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-iE25PxIJ6V0C6krReLquVw6R0QTsRTmEQc4K2Co3P6zsimU/jltcDBKYDy1h/5j9S/fqmMeXnpM+9LEWKJKI6A=="], - "react-native-update": ["react-native-update@10.29.0", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-TFGwJxI62OHPJimxMnI8PDvUBhZio1alsgIvXHYh1oYAZYYejkUvwl+Ojdbm58IKoZzxAaT7RvD1qGdvlg/oKg=="], + "react-native-update": ["react-native-update@10.29.4", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-leQX3dq4yBi/oFn0l06nXd7OOFnZnlcMIrAXH7vgTRsqXCdYLoSsZXXkcSYxncn8tBqzh02w4880mlqouve6Sg=="], "react-native-url-polyfill": ["react-native-url-polyfill@2.0.0", "", { "dependencies": { "whatwg-url-without-unicode": "8.0.0-3" }, "peerDependencies": { "react-native": "*" } }, "sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA=="], diff --git a/Example/testHotUpdate/ios/AwesomeProject/AppDelegate.mm b/Example/testHotUpdate/ios/AwesomeProject/AppDelegate.mm index 93c9526..8ddab2b 100644 --- a/Example/testHotUpdate/ios/AwesomeProject/AppDelegate.mm +++ b/Example/testHotUpdate/ios/AwesomeProject/AppDelegate.mm @@ -2,12 +2,14 @@ #import "RCTPushy.h" #import +#import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.moduleName = @"AwesomeProject"; + self.dependencyProvider = [RCTAppDependencyProvider new]; // You can add your custom initial props in the dictionary below. // They will be passed down to the ViewController used by React Native. self.initialProps = @{}; diff --git a/Example/testHotUpdate/ios/Podfile.lock b/Example/testHotUpdate/ios/Podfile.lock index 3c3d4cd..8729223 100644 --- a/Example/testHotUpdate/ios/Podfile.lock +++ b/Example/testHotUpdate/ios/Podfile.lock @@ -1332,7 +1332,7 @@ PODS: - React-jsiexecutor - React-RCTFBReactNativeSpec - ReactCommon/turbomodule/core - - react-native-safe-area-context (5.4.1): + - react-native-safe-area-context (5.5.0): - DoubleConversion - glog - hermes-engine @@ -1347,8 +1347,8 @@ PODS: - React-hermes - React-ImageManager - React-jsi - - react-native-safe-area-context/common (= 5.4.1) - - react-native-safe-area-context/fabric (= 5.4.1) + - react-native-safe-area-context/common (= 5.5.0) + - react-native-safe-area-context/fabric (= 5.5.0) - React-NativeModulesApple - React-RCTFabric - React-renderercss @@ -1358,7 +1358,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-safe-area-context/common (5.4.1): + - react-native-safe-area-context/common (5.5.0): - DoubleConversion - glog - hermes-engine @@ -1382,7 +1382,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-safe-area-context/fabric (5.4.1): + - react-native-safe-area-context/fabric (5.5.0): - DoubleConversion - glog - hermes-engine @@ -1407,7 +1407,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-update (10.28.11): + - react-native-update (10.29.4): - DoubleConversion - glog - hermes-engine @@ -1423,8 +1423,8 @@ PODS: - React-hermes - React-ImageManager - React-jsi - - react-native-update/HDiffPatch (= 10.28.11) - - react-native-update/RCTPushy (= 10.28.11) + - react-native-update/HDiffPatch (= 10.29.4) + - react-native-update/RCTPushy (= 10.29.4) - React-NativeModulesApple - React-RCTFabric - React-renderercss @@ -1435,7 +1435,7 @@ PODS: - ReactCommon/turbomodule/core - SSZipArchive - Yoga - - react-native-update/HDiffPatch (10.28.11): + - react-native-update/HDiffPatch (10.29.4): - DoubleConversion - glog - hermes-engine @@ -1461,7 +1461,7 @@ PODS: - ReactCommon/turbomodule/core - SSZipArchive - Yoga - - react-native-update/RCTPushy (10.28.11): + - react-native-update/RCTPushy (10.29.4): - DoubleConversion - glog - hermes-engine @@ -1809,7 +1809,7 @@ PODS: - React-logger (= 0.79.2) - React-perflogger (= 0.79.2) - React-utils (= 0.79.2) - - ReactNativeCameraKit (15.0.1): + - ReactNativeCameraKit (15.1.0): - DoubleConversion - glog - hermes-engine @@ -2186,8 +2186,8 @@ SPEC CHECKSUMS: React-logger: 8edfcedc100544791cd82692ca5a574240a16219 React-Mapbuffer: c3f4b608e4a59dd2f6a416ef4d47a14400194468 React-microtasksnativemodule: 054f34e9b82f02bd40f09cebd4083828b5b2beb6 - react-native-safe-area-context: 5594ec631ede9c311c5c0efa244228eff845ce88 - react-native-update: b4a6653129ac98d9cf5295d40b43ffb927114237 + react-native-safe-area-context: 11d29ae675265669f498d7d9de2341087e8fe162 + react-native-update: 6d3a3eb322cbc382ad78853cb52e44e8c93e8072 React-NativeModulesApple: 2c4377e139522c3d73f5df582e4f051a838ff25e React-oscompat: ef5df1c734f19b8003e149317d041b8ce1f7d29c React-perflogger: 9a151e0b4c933c9205fd648c246506a83f31395d @@ -2219,7 +2219,7 @@ SPEC CHECKSUMS: ReactAppDependencyProvider: 04d5eb15eb46be6720e17a4a7fa92940a776e584 ReactCodegen: c63eda03ba1d94353fb97b031fc84f75a0d125ba ReactCommon: 76d2dc87136d0a667678668b86f0fca0c16fdeb0 - ReactNativeCameraKit: caf4175d93930ac5267fb98c462f5f1b8d543830 + ReactNativeCameraKit: e542035174335357fd7d747089f0e09a4ed27365 RNSVG: 8a1054afe490b5d63b9792d7ae3c1fde8c05cdd0 RNVectorIcons: 941a39b5d3b9d8cf8ac2e2fc09b07bfafbcf9796 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 diff --git a/Example/testHotUpdate/package.json b/Example/testHotUpdate/package.json index 508ebff..dae055f 100644 --- a/Example/testHotUpdate/package.json +++ b/Example/testHotUpdate/package.json @@ -14,15 +14,15 @@ "dev:harmony": "react-native bundle-harmony --dev" }, "dependencies": { - "form-data": "^4.0.2", + "form-data": "^4.0.3", "patch-package": "^8.0.0", "react": "19.0.0", "react-native": "0.79.2", - "react-native-camera-kit": "^15.0.1", + "react-native-camera-kit": "^15.1.0", "react-native-paper": "^5.14.5", - "react-native-safe-area-context": "^5.4.1", + "react-native-safe-area-context": "^5.5.0", "react-native-svg": "^15.12.0", - "react-native-update": "^10.29.0", + "react-native-update": "^10.29.4", "react-native-vector-icons": "^10.2.0" }, "devDependencies": { diff --git a/Example/testHotUpdate/update.json b/Example/testHotUpdate/update.json index 424e7c1..eef421e 100644 --- a/Example/testHotUpdate/update.json +++ b/Example/testHotUpdate/update.json @@ -1,7 +1,7 @@ { "ios": { - "appId": 24794, - "appKey": "SqShg4Klnj2hG6LAFMW2PdcgSSuniz0T" + "appId": 28943, + "appKey": "d-OmPxIBivPrDfKhLHjxN-HS" }, "android": { "appId": 27509, diff --git a/ios/RCTPushy/RCTPushy.mm b/ios/RCTPushy/RCTPushy.mm index f5b16f1..6655d5b 100644 --- a/ios/RCTPushy/RCTPushy.mm +++ b/ios/RCTPushy/RCTPushy.mm @@ -93,8 +93,7 @@ RCT_EXPORT_MODULE(RCTPushy); BOOL needRollback = (!ignoreRollback && isFirstTime == NO && isFirstLoadOK == NO) || loadVersion.length<=0; if (needRollback) { loadVersion = [self rollback]; - } - else if (isFirstTime && !ignoreRollback){ + } else if (isFirstTime && !ignoreRollback){ // bundleURL may be called many times, ignore rollbacks before process restarted again. ignoreRollback = true; @@ -302,34 +301,35 @@ RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options resolve(@true); - }else{ + } else { reject(@"执行报错", nil, nil); } } RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve - rejecter:(RCTPromiseRejectBlock)reject) + rejecter:(RCTPromiseRejectBlock)reject) { @try { NSString *hash = options[@"hash"]; if (hash.length) { - [self setNeedUpdate:options resolver:resolve rejecter:reject]; - - // reload in earlier version - dispatch_async(dispatch_get_main_queue(), ^{ - [self.bridge setValue:[[self class] bundleURL] forKey:@"bundleURL"]; - [self.bridge reload]; - }); - - #if __has_include("RCTReloadCommand.h") - // reload 0.62+ - RCTReloadCommandSetBundleURL([[self class] bundleURL]); - RCTTriggerReloadCommandListeners(@"pushy reload"); - #endif - - resolve(@true); - }else{ + // 只在 setNeedUpdate 成功后 resolve + [self setNeedUpdate:options resolver:^(id result) { + // reload in earlier version + dispatch_async(dispatch_get_main_queue(), ^{ + [self.bridge setValue:[[self class] bundleURL] forKey:@"bundleURL"]; + [self.bridge reload]; + }); + #if __has_include("RCTReloadCommand.h") + // reload 0.62+ + RCTReloadCommandSetBundleURL([[self class] bundleURL]); + RCTTriggerReloadCommandListeners(@"pushy reload"); + #endif + resolve(@true); + } rejecter:^(NSString *code, NSString *message, NSError *error) { + reject(code, message, error); + }]; + } else { reject(@"执行报错", nil, nil); } } diff --git a/package.json b/package.json index 93a082c..e4f9187 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-update", - "version": "10.29.4", + "version": "10.29.5", "description": "react-native hot update", "main": "src/index", "scripts": {