react-native-ota-hot-update 2.3.2 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -118,22 +118,26 @@ var taskIdentifier: UIBackgroundTaskIdentifier = .invalid
118
118
  ...
119
119
  ```
120
120
  ```bash
121
- override func applicationWillResignActive(_ application: UIApplication) {
122
- // End any existing background task
123
- if taskIdentifier != .invalid {
124
- application.endBackgroundTask(taskIdentifier)
125
- taskIdentifier = .invalid
126
- }
127
-
128
- // Start a new background task
129
- taskIdentifier = application.beginBackgroundTask(withName: nil) { [weak self] in
130
- if let strongSelf = self {
131
- application.endBackgroundTask(strongSelf.taskIdentifier)
132
- strongSelf.taskIdentifier = .invalid
133
- }
134
- }
121
+ public override func applicationDidEnterBackground(_ application: UIApplication) {
122
+ if taskIdentifier != .invalid {
123
+ application.endBackgroundTask(taskIdentifier)
124
+ taskIdentifier = .invalid
125
+ }
126
+
127
+ taskIdentifier = application.beginBackgroundTask(withName: "OTAUpdate") { [weak self] in
128
+ if let strongSelf = self {
129
+ application.endBackgroundTask(strongSelf.taskIdentifier)
130
+ strongSelf.taskIdentifier = .invalid
135
131
  }
136
-
132
+ }
133
+ }
134
+
135
+ public override func applicationWillEnterForeground(_ application: UIApplication) {
136
+ if taskIdentifier != .invalid {
137
+ application.endBackgroundTask(taskIdentifier)
138
+ taskIdentifier = .invalid
139
+ }
140
+ }
137
141
  ```
138
142
 
139
143
 
@@ -3,7 +3,7 @@ package com.otahotupdate
3
3
  import android.content.Context
4
4
  import android.content.pm.PackageManager
5
5
  import android.os.Build
6
- import com.facebook.react.TurboReactPackage
6
+ import com.facebook.react.BaseReactPackage
7
7
  import com.facebook.react.bridge.NativeModule
8
8
  import com.facebook.react.bridge.ReactApplicationContext
9
9
  import com.facebook.react.module.model.ReactModuleInfo
@@ -15,7 +15,7 @@ import com.rnhotupdate.Common.VERSION
15
15
  import com.rnhotupdate.SharedPrefs
16
16
 
17
17
 
18
- class OtaHotUpdate : TurboReactPackage() {
18
+ class OtaHotUpdate : BaseReactPackage() {
19
19
  override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
20
20
  return if (name == OtaHotUpdateModule.NAME) {
21
21
  OtaHotUpdateModule(reactContext)
@@ -33,7 +33,6 @@ class OtaHotUpdate : TurboReactPackage() {
33
33
  OtaHotUpdateModule.NAME,
34
34
  false, // canOverrideExistingModule
35
35
  false, // needsEagerInit
36
- true, // hasConstants
37
36
  false, // isCxxModule
38
37
  isTurboModule // isTurboModule
39
38
  )
@@ -68,6 +67,9 @@ class OtaHotUpdate : TurboReactPackage() {
68
67
  val version = sharedPrefs.getString(VERSION)
69
68
  val currentVersionName = sharedPrefs.getString(CURRENT_VERSION_CODE)
70
69
  if (pathBundle == "" || (currentVersionName != context.getVersionCode())) {
70
+ if (pathBundle != "") {
71
+ sharedPrefs.putString(PATH, "")
72
+ }
71
73
  if (version != "") {
72
74
  // reset version number because bundle is wrong version, need download from new version
73
75
  sharedPrefs.putString(VERSION, "")
@@ -141,13 +141,18 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
141
141
 
142
142
  @ReactMethod
143
143
  override fun setExactBundlePath(path: String?, promise: Promise) {
144
- val sharedPrefs = SharedPrefs(reactApplicationContext)
145
- sharedPrefs.putString(PATH, path)
146
- sharedPrefs.putString(
147
- CURRENT_VERSION_CODE,
148
- reactApplicationContext.getVersionCode()
149
- )
150
- promise.resolve(true)
144
+ val file = File(path)
145
+ if (file.exists() && file.isFile) {
146
+ val sharedPrefs = SharedPrefs(reactApplicationContext)
147
+ sharedPrefs.putString(PATH, path)
148
+ sharedPrefs.putString(
149
+ CURRENT_VERSION_CODE,
150
+ reactApplicationContext.getVersionCode()
151
+ )
152
+ promise.resolve(true)
153
+ } else {
154
+ promise.resolve(false)
155
+ }
151
156
  }
152
157
 
153
158
  @ReactMethod
@@ -162,6 +162,7 @@ void OTAExceptionHandler(NSException *exception) {
162
162
  } else {
163
163
  // reset version number because bundle is wrong version, need download from new version
164
164
  [defaults removeObjectForKey:@"VERSION"];
165
+ [defaults removeObjectForKey:@"PATH"];
165
166
  [defaults synchronize];
166
167
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
167
168
  }
@@ -394,7 +395,7 @@ RCT_EXPORT_METHOD(getUpdateMetadata:(double)a
394
395
  RCT_EXPORT_METHOD(setExactBundlePath:(NSString *)path
395
396
  resolve:(RCTPromiseResolveBlock)resolve
396
397
  reject:(RCTPromiseRejectBlock)reject) {
397
- if (path) {
398
+ if ([OtaHotUpdate isFilePathValid:path]) {
398
399
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
399
400
  [defaults setObject:path forKey:@"PATH"];
400
401
  [defaults setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forKey:@"VERSION_NAME"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ota-hot-update",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "description": "Hot update for react native",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.license = package["license"]
12
12
  s.authors = package["author"]
13
13
 
14
- s.platforms = { :ios => "15.5" }
14
+ s.platforms = { :ios => min_ios_version_supported }
15
15
  s.source = { :git => "https://github.com/vantuan88291/react-native-ota-hot-update.git", :tag => "#{s.version}" }
16
16
  s.pod_target_xcconfig = {
17
17
  'SWIFT_VERSION' => '5.0',
@@ -19,7 +19,7 @@ Pod::Spec.new do |s|
19
19
  }
20
20
  s.public_header_files = "ios/OtaHotUpdate.h"
21
21
  s.source_files = "ios/**/*.{h,m,mm,cpp}"
22
- s.dependency 'SSZipArchive', '>= 2.5.5', '< 3.0'
22
+ s.dependency 'SSZipArchive', '~> 2.4.3'
23
23
  if ENV['RCT_NEW_ARCH_ENABLED'] == '0'
24
24
  s.exclude_files = "ios/generated"
25
25
  end