diff --git a/Example/testHotUpdate/ios/AwesomeProject/AppDelegate.mm b/Example/testHotUpdate/ios/AwesomeProject/AppDelegate.mm index 71edbe9..63b3d5f 100644 --- a/Example/testHotUpdate/ios/AwesomeProject/AppDelegate.mm +++ b/Example/testHotUpdate/ios/AwesomeProject/AppDelegate.mm @@ -1,5 +1,5 @@ #import "AppDelegate.h" - +#import "RCTPushy.h" #import #import #import @@ -87,7 +87,7 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot"; #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else - return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; + return [RCTPushy bundleURL]; #endif } diff --git a/Example/testHotUpdate/ios/AwesomeProject/Info.plist b/Example/testHotUpdate/ios/AwesomeProject/Info.plist index 03e8712..d66ce91 100644 --- a/Example/testHotUpdate/ios/AwesomeProject/Info.plist +++ b/Example/testHotUpdate/ios/AwesomeProject/Info.plist @@ -24,6 +24,19 @@ 1 LSRequiresIPhoneOS + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + NSExceptionDomains + + localhost + + NSExceptionAllowsInsecureHTTPLoads + + + + NSLocationWhenInUseUsageDescription UILaunchStoryboardName @@ -40,18 +53,5 @@ UIViewControllerBasedStatusBarAppearance - NSAppTransportSecurity - - NSAllowsArbitraryLoads - - NSExceptionDomains - - localhost - - NSExceptionAllowsInsecureHTTPLoads - - - - diff --git a/ios/RCTPushy/RCTPushy.mm b/ios/RCTPushy/RCTPushy.mm index 850ef32..8f53f06 100644 --- a/ios/RCTPushy/RCTPushy.mm +++ b/ios/RCTPushy/RCTPushy.mm @@ -53,6 +53,7 @@ typedef NS_ENUM(NSInteger, PushyType) { }; static BOOL ignoreRollback = false; +static BOOL isUsingBundleUrl = false; @implementation RCTPushy { RCTPushyManager *_fileManager; @@ -65,6 +66,7 @@ RCT_EXPORT_MODULE(RCTPushy); + (NSURL *)bundleURL { + isUsingBundleUrl = true; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo]; @@ -161,6 +163,7 @@ RCT_EXPORT_MODULE(RCTPushy); ret[@"uuid"] = [defaults objectForKey:keyUuid]; NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo]; ret[@"currentVersion"] = [pushyInfo objectForKey:paramCurrentVersion]; + ret[@"isUsingBundleUrl"] = @(isUsingBundleUrl); // clear isFirstTimemarked if (ret[@"isFirstTime"]) { diff --git a/lib/NativeUpdate.js b/lib/NativeUpdate.ts similarity index 57% rename from lib/NativeUpdate.js rename to lib/NativeUpdate.ts index b3a4c46..0289a56 100644 --- a/lib/NativeUpdate.js +++ b/lib/NativeUpdate.ts @@ -1,51 +1,45 @@ -/** - * @format - * @flow strict-local - */ -'use strict'; - import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport'; import { TurboModuleRegistry } from 'react-native'; export interface Spec extends TurboModule { getConstants: () => { - downloadRootDir: string, - packageVersion: string, - currentVersion: string, - isFirstTime: boolean, - rolledBackVersion: string, - buildTime: string, - blockUpdate: Object, - uuid: string, - isUsingBundleUrl: boolean, + downloadRootDir: string; + packageVersion: string; + currentVersion: string; + isFirstTime: boolean; + rolledBackVersion: string; + buildTime: string; + blockUpdate: Object; + uuid: string; + isUsingBundleUrl: boolean; }; setLocalHashInfo(hash: string, info: string): Promise; getLocalHashInfo(hash: string): Promise; setUuid(uuid: string): Promise; - setBlockUpdate(options: { reason: string, until: number }): Promise; + setBlockUpdate(options: { reason: string; until: number }): Promise; reloadUpdate(options: { hash: string }): Promise; setNeedUpdate(options: { hash: string }): Promise; markSuccess(): Promise; downloadPatchFromPpk(options: { - updateUrl: string, - hash: string, - originHash: string, + updateUrl: string; + hash: string; + originHash: string; }): Promise; downloadPatchFromPackage(options: { - updateUrl: string, - hash: string, + updateUrl: string; + hash: string; }): Promise; downloadFullUpdate(options: { - updateUrl: string, - hash: string, + updateUrl: string; + hash: string; }): Promise; downloadAndInstallApk(options: { - url: string, - target: string, - hash: string, + url: string; + target: string; + hash: string; }): Promise; addListener(eventName: string): void; removeListeners(count: number): void; } -export default (TurboModuleRegistry.get('Pushy'): ?Spec); +export default TurboModuleRegistry.get('Pushy') as Spec | null; diff --git a/lib/main.ts b/lib/main.ts index f1f3f32..acb22b0 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -44,7 +44,7 @@ export const buildTime = PushyConstants.buildTime; let blockUpdate = PushyConstants.blockUpdate; let uuid = PushyConstants.uuid; -if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) { +if (!PushyConstants.isUsingBundleUrl) { throw new Error( 'react-native-update模块无法加载,请对照文档检查Bundle URL的配置', ); diff --git a/react-native-update.podspec b/react-native-update.podspec index 7fbfedd..c049386 100644 --- a/react-native-update.podspec +++ b/react-native-update.podspec @@ -1,8 +1,7 @@ require 'json' package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) -folly_version = '2021.06.28.00-v2' -folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' + Pod::Spec.new do |s| s.name = package['name'] s.version = package['version'] @@ -41,18 +40,5 @@ Pod::Spec.new do |s| 'android/jni/lzma/C/Lzma2Dec.{h,c}'] ss.private_header_files = 'ios/RCTPushy/HDiffPatch/**/*.h' end - # This guard prevent to install the dependencies when we run `pod install` in the old architecture. -if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then - s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" - s.pod_target_xcconfig = { - "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" - } - - s.dependency "React-Codegen" - s.dependency "RCT-Folly", folly_version - s.dependency "RCTRequired" - s.dependency "RCTTypeSafety" - s.dependency "ReactCommon/turbomodule/core" -end + install_modules_dependencies(s) end