react-native-ota-hot-update 1.1.0 → 1.1.1

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
@@ -36,6 +36,31 @@ Open `AppDelegate.m` and add this:
36
36
  #endif
37
37
  }
38
38
  ```
39
+ #### For downloading in background mode on IOS, following this (optional):
40
+
41
+ AppDelegate.h:
42
+ ```bash
43
+ @property (nonatomic, assign) UIBackgroundTaskIdentifier taskIdentifier;
44
+ ```
45
+ AppDelegate.mm:
46
+
47
+ ```bash
48
+ - (void)applicationWillResignActive:(UIApplication *)application {
49
+ if (self.taskIdentifier != UIBackgroundTaskInvalid) {
50
+ [application endBackgroundTask:self.taskIdentifier];
51
+ self.taskIdentifier = UIBackgroundTaskInvalid;
52
+ }
53
+
54
+ __weak AppDelegate *weakSelf = self;
55
+ self.taskIdentifier = [application beginBackgroundTaskWithName:nil expirationHandler:^{
56
+ if (weakSelf) {
57
+ [application endBackgroundTask:weakSelf.taskIdentifier];
58
+ weakSelf.taskIdentifier = UIBackgroundTaskInvalid;
59
+ }
60
+ }];
61
+ }
62
+ ```
63
+
39
64
 
40
65
  ### Android
41
66
  Open `MainApplication.java/kt` and add these codes bellow:
@@ -53,12 +78,24 @@ override fun getJSBundleFile(): String? {
53
78
  Here is the guideline to control bundle js by yourself, in here i am using Firebase storage to store bundlejs file and a json file that announce new version is comming:
54
79
 
55
80
  #### 1.Add these script into your package.json to export bundlejs file:
81
+
82
+ - For react native CLI:
56
83
  ```bash
57
84
  "scripts": {
58
85
  "export-android": "mkdir -p android/output && react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/output/index.android.bundle --assets-dest android/output && cd android && find output -type f | zip index.android.bundle.zip -@ && cd .. && rm -rf android/output",
59
86
  "export-ios": "mkdir -p ios/output && react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ios/output/main.jsbundle --assets-dest ios/output && cd ios && find output -type f | zip main.jsbundle.zip -@ && cd .. && rm -rf ios/output"
60
87
  }
61
88
  ```
89
+ - For expo / expo bare project:
90
+
91
+ ```bash
92
+ "scripts": {
93
+ "export-android": "mkdir -p android/output && npx expo export:embed --platform android --entry-file node_modules/expo/AppEntry.js --bundle-output android/output/index.android.bundle --dev false --assets-dest android/output && cd android && find output -type f | zip index.android.bundle.zip -@ && cd .. && rm -rf android/output",
94
+ "export-ios": "mkdir -p ios/output && npx expo export:embed --platform ios --entry-file node_modules/expo/AppEntry.js --bundle-output ios/output/main.jsbundle --dev false --assets-dest ios/output && cd ios && find output -type f | zip main.jsbundle.zip -@ && cd .. && rm -rf ios/output"
95
+ }
96
+ ```
97
+ For expo you might need check path of `--entry-file node_modules/expo/AppEntry.js`, get it from package.json / main
98
+
62
99
  These commands are export bundle file and compress it as a zip file, one for android and one for ios. You can create your own script that export and auto upload to your server.
63
100
 
64
101
  Then create an json file: `update.json` like that:
@@ -100,6 +137,18 @@ After you have done everything related to version manager, you just handle the w
100
137
 
101
138
  The important thing: this library will control `version` by it self, need always pass version as parameter in `downloadBundleUri`, it will storage as a cache and use this to check whether need update version in the next time. Default of `version` is **0**
102
139
 
140
+ ## Tips for manage bundles
141
+
142
+ In this demo project i have used firebase storage to control the bundles and version, but that is not useful. I would like to suggest you to use some CMS to control the bundles.
143
+ For CMS, it has a lot open sources, now i am using strapi CMS to control the version, i also create auto release script like code push and can integrate with CI/CD. Here is some screenshot of strapi CMS:
144
+
145
+ ![](https://github.com/vantuan88291/react-native-ota-hot-update/raw/main/scr2.png)
146
+
147
+ ![](https://github.com/vantuan88291/react-native-ota-hot-update/raw/main/scr3.png)
148
+
149
+ Beside strapi you can also try craftcms, payloadcms...
150
+ You can refer folder sampleComponent, it has the logic of update with CMS and also include script auto upload the bundle to CMS.
151
+ Contact me via email if you want to implement hot update via CMS (need service fee)
103
152
 
104
153
  ## Functions
105
154
 
@@ -122,7 +171,7 @@ The important thing: this library will control `version` by it self, need always
122
171
  | updateFail(message: string) | No | Callback | Will trigger when install update failed |
123
172
  | restartAfterInstall | No | boolean | default is `false`, if `true` will restart the app after install success to apply the new change |
124
173
  | progress | No | void | A callback to show progress when downloading bundle |
125
- | extensionBundle | No | string | extension of bundle js file, default is .bundle, for expo project you might set .hbc |
174
+ | extensionBundle | No | string | extension of bundle js file, default is .bundle for android, ios is .jsbundle |
126
175
 
127
176
  ## DownloadManager
128
177
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ota-hot-update",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Hot update for react native",
5
5
  "main": "src/index",
6
6
  "repository": "https://github.com/vantuan88291/react-native-ota-hot-update",
package/src/index.tsx CHANGED
@@ -28,6 +28,7 @@ const downloadBundleFile = async (downloadManager: DownloadManager, uri: string,
28
28
  const res = await downloadManager
29
29
  .config({
30
30
  fileCache: Platform.OS === 'android',
31
+ IOSBackgroundTask: true,
31
32
  })
32
33
  .fetch('GET', uri, {
33
34
  ...headers,