react-native-ota-hot-update 2.3.3 → 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
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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.
|
|
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 :
|
|
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
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
package/ios/OtaHotUpdate.mm
CHANGED
|
@@ -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
|
-
|
|
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"];
|