@appzung/react-native-code-push 5.7.1 → 6.4.2

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.
Files changed (114) hide show
  1. package/CONTRIBUTING.md +17 -19
  2. package/CodePush.js +11 -4
  3. package/CodePush.podspec +3 -3
  4. package/README.md +93 -37
  5. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +44 -7
  6. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +0 -0
  7. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +77 -22
  8. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +14 -0
  9. package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +15 -1
  10. package/android/app/src/main/java/com/microsoft/codepush/react/TLSSocketFactory.java +72 -0
  11. package/android/codepush.gradle +1 -1
  12. package/docs/api-android.md +21 -3
  13. package/docs/api-js.md +3 -3
  14. package/docs/multi-deployment-testing-android.md +63 -22
  15. package/docs/multi-deployment-testing-ios.md +17 -11
  16. package/docs/setup-android.md +79 -19
  17. package/docs/setup-ios.md +57 -7
  18. package/docs/setup-windows.md +1 -1
  19. package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +0 -0
  20. package/ios/CodePush/CodePush.m +104 -24
  21. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +0 -0
  22. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +0 -0
  23. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +0 -0
  24. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +0 -0
  25. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +0 -0
  26. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +0 -0
  27. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +0 -0
  28. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +0 -0
  29. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +0 -0
  30. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +0 -0
  31. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +0 -0
  32. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +0 -0
  33. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +0 -0
  34. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +0 -0
  35. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +0 -0
  36. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +0 -0
  37. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +0 -0
  38. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +0 -0
  39. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +0 -0
  40. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +0 -0
  41. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +0 -0
  42. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +0 -0
  43. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +0 -0
  44. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +0 -0
  45. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +0 -0
  46. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +0 -0
  47. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +0 -0
  48. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +0 -0
  49. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +0 -0
  50. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +0 -0
  51. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +0 -0
  52. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +0 -0
  53. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +0 -0
  54. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +0 -0
  55. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +0 -0
  56. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +0 -0
  57. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +0 -0
  58. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +0 -0
  59. package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +0 -0
  60. package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +0 -0
  61. package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +0 -0
  62. package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +0 -0
  63. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +0 -0
  64. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +0 -0
  65. package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +0 -0
  66. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +0 -0
  67. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +0 -0
  68. package/ios/CodePush/SSZipArchive/Common.h +0 -0
  69. package/ios/CodePush/SSZipArchive/SSZipArchive.h +0 -0
  70. package/ios/CodePush/SSZipArchive/SSZipArchive.m +0 -0
  71. package/ios/CodePush/SSZipArchive/aes/aes.h +0 -0
  72. package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +0 -0
  73. package/ios/CodePush/SSZipArchive/aes/aescrypt.c +0 -0
  74. package/ios/CodePush/SSZipArchive/aes/aeskey.c +0 -0
  75. package/ios/CodePush/SSZipArchive/aes/aesopt.h +0 -0
  76. package/ios/CodePush/SSZipArchive/aes/aestab.c +0 -0
  77. package/ios/CodePush/SSZipArchive/aes/aestab.h +0 -0
  78. package/ios/CodePush/SSZipArchive/aes/brg_endian.h +0 -0
  79. package/ios/CodePush/SSZipArchive/aes/brg_types.h +0 -0
  80. package/ios/CodePush/SSZipArchive/aes/entropy.c +0 -0
  81. package/ios/CodePush/SSZipArchive/aes/entropy.h +0 -0
  82. package/ios/CodePush/SSZipArchive/aes/fileenc.c +0 -0
  83. package/ios/CodePush/SSZipArchive/aes/fileenc.h +0 -0
  84. package/ios/CodePush/SSZipArchive/aes/hmac.c +0 -0
  85. package/ios/CodePush/SSZipArchive/aes/hmac.h +0 -0
  86. package/ios/CodePush/SSZipArchive/aes/prng.c +0 -0
  87. package/ios/CodePush/SSZipArchive/aes/prng.h +0 -0
  88. package/ios/CodePush/SSZipArchive/aes/pwd2key.c +0 -0
  89. package/ios/CodePush/SSZipArchive/aes/pwd2key.h +0 -0
  90. package/ios/CodePush/SSZipArchive/aes/sha1.c +0 -0
  91. package/ios/CodePush/SSZipArchive/aes/sha1.h +0 -0
  92. package/ios/CodePush/SSZipArchive/minizip/crypt.h +0 -0
  93. package/ios/CodePush/SSZipArchive/minizip/ioapi.c +0 -0
  94. package/ios/CodePush/SSZipArchive/minizip/ioapi.h +0 -0
  95. package/ios/CodePush/SSZipArchive/minizip/mztools.c +0 -0
  96. package/ios/CodePush/SSZipArchive/minizip/mztools.h +0 -0
  97. package/ios/CodePush/SSZipArchive/minizip/unzip.c +0 -0
  98. package/ios/CodePush/SSZipArchive/minizip/unzip.h +0 -0
  99. package/ios/CodePush/SSZipArchive/minizip/zip.c +0 -0
  100. package/ios/CodePush/SSZipArchive/minizip/zip.h +0 -0
  101. package/package-mixins.js +2 -3
  102. package/package.json +36 -13
  103. package/react-native.config.js +10 -0
  104. package/request-fetch-adapter.js +1 -1
  105. package/scripts/generateBundledResourcesHash.js +1 -1
  106. package/scripts/postlink/android/postlink.js +2 -2
  107. package/scripts/postunlink/android/postunlink.js +3 -3
  108. package/scripts/tools/linkToolsAndroid.js +1 -1
  109. package/scripts/tools/linkToolsIos.js +2 -2
  110. package/tsconfig.json +14 -0
  111. package/tslint.json +32 -0
  112. package/typings/react-native-code-push.d.ts +14 -5
  113. package/RestartManager.js +0 -59
  114. package/gulpfile.js +0 -302
@@ -1,10 +1,11 @@
1
1
  ## Android Setup
2
2
 
3
- * [Plugin Installation (Android)](#plugin-installation-android)
3
+ * [Plugin Installation and Configuration for React Native 0.60 version and above](#plugin-installation-and-configuration-for-react-native-060-version-and-above-android)
4
+ * [Plugin Installation for React Native lower than 0.60 (Android)](#plugin-installation-for-react-native-lower-than-060-android)
4
5
  * [Plugin Installation (Android - RNPM)](#plugin-installation-android---rnpm)
5
6
  * [Plugin Installation (Android - Manual)](#plugin-installation-android---manual)
6
- * [Plugin Configuration (Android)](#plugin-configuration-android)
7
- * [For React Native >= v0.29](#for-react-native--v029)
7
+ * [Plugin Configuration for React Native lower than 0.60 (Android)](#plugin-configuration-for-react-native-lower-than-060-android)
8
+ * [For React Native v0.29 - v0.59](#for-react-native-v029---v059)
8
9
  * [For newly created React Native application](#for-newly-created-react-native-application)
9
10
  * [For existing native application](#for-existing-native-application)
10
11
  * [For React Native v0.19 - v0.28](#for-react-native-v019---v028)
@@ -12,11 +13,72 @@
12
13
  * [For React Native >= v0.29 (Background React Instances)](#for-react-native--v029-background-react-instances)
13
14
  * [For React Native v0.19 - v0.28 (Background React Instances)](#for-react-native-v019---v028-background-react-instances)
14
15
  * [WIX React Native Navigation applications (ver 1.x)](#wix-react-native-navigation-applications)
15
- * [Code Signing setup](#code-signing-setup)
16
+ * [Code Signing setup](#code-signing-setup)
16
17
 
17
18
  In order to integrate CodePush into your Android project, please perform the following steps:
18
19
 
19
- ### Plugin Installation (Android)
20
+ ### Plugin Installation and Configuration for React Native 0.60 version and above (Android)
21
+
22
+ 1. In your `android/settings.gradle` file, make the following additions at the end of the file:
23
+
24
+ ```gradle
25
+ ...
26
+ include ':app', ':react-native-code-push'
27
+ project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
28
+ ```
29
+
30
+ 2. In your `android/app/build.gradle` file, add the `codepush.gradle` file as an additional build task definition underneath `react.gradle`:
31
+
32
+ ```gradle
33
+ ...
34
+ apply from: "../../node_modules/react-native/react.gradle"
35
+ apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
36
+ ...
37
+ ```
38
+
39
+ 3. Update the `MainApplication.java` file to use CodePush via the following changes:
40
+
41
+ ```java
42
+ ...
43
+ // 1. Import the plugin class.
44
+ import com.microsoft.codepush.react.CodePush;
45
+
46
+ public class MainApplication extends Application implements ReactApplication {
47
+
48
+ private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
49
+ ...
50
+
51
+ // 2. Override the getJSBundleFile method in order to let
52
+ // the CodePush runtime determine where to get the JS
53
+ // bundle location from on each app start
54
+ @Override
55
+ protected String getJSBundleFile() {
56
+ return CodePush.getJSBundleFile();
57
+ }
58
+ };
59
+ }
60
+ ```
61
+
62
+ 4. Add the Deployment key to `strings.xml`:
63
+
64
+ To let the CodePush runtime know which deployment it should query for updates, open your app's `strings.xml` file and add a new string named `CodePushDeploymentKey`, whose value is the key of the deployment you want to configure this app against (like the key for the `Staging` deployment for the `FooBar` app). You can retrieve this value by running `appcenter codepush deployment list -a <ownerName>/<appName> -k` in the CodePush CLI (the `-k` flag is necessary since keys aren't displayed by default) and copying the value of the `Key` column which corresponds to the deployment you want to use (see below). Note that using the deployment's name (like Staging) will not work. The "friendly name" is intended only for authenticated management usage from the CLI, and not for public consumption within your app.
65
+
66
+ ![Deployment list](https://cloud.githubusercontent.com/assets/116461/11601733/13011d5e-9a8a-11e5-9ce2-b100498ffb34.png)
67
+
68
+ In order to effectively make use of the `Staging` and `Production` deployments that were created along with your CodePush app, refer to the [multi-deployment testing](../README.md#multi-deployment-testing) docs below before actually moving your app's usage of CodePush into production.
69
+
70
+ Your `strings.xml` should looks like this:
71
+
72
+ ```xml
73
+ <resources>
74
+ <string name="app_name">AppName</string>
75
+ <string moduleConfig="true" name="CodePushDeploymentKey">DeploymentKey</string>
76
+ </resources>
77
+ ```
78
+
79
+ *Note: If you need to dynamically use a different deployment, you can also override your deployment key in JS code using [Code-Push options](./api-js.md#CodePushOptions)*
80
+
81
+ ### Plugin Installation for React Native lower than 0.60 (Android)
20
82
 
21
83
  In order to accommodate as many developer preferences as possible, the CodePush plugin supports Android installation via two mechanisms:
22
84
 
@@ -40,9 +102,9 @@ In order to accommodate as many developer preferences as possible, the CodePush
40
102
 
41
103
  *Note: If you don't already have RNPM installed, you can do so by simply running `npm i -g rnpm` and then executing the above command.*
42
104
 
43
- 2. If you're using RNPM >=1.6.0, you will be prompted for the deployment key you'd like to use. If you don't already have it, you can retreive this value by running `code-push deployment ls <appName> -k`, or you can choose to ignore it (by simply hitting `<ENTER>`) and add it in later. To get started, we would recommend just using your `Staging` deployment key, so that you can test out the CodePush end-to-end.
105
+ 2. If you're using RNPM >=1.6.0, you will be prompted for the deployment key you'd like to use. If you don't already have it, you can retrieve this value by running `appcenter codepush deployment list -a <ownerName>/<appName> -k`, or you can choose to ignore it (by simply hitting `<ENTER>`) and add it in later. To get started, we would recommend just using your `Staging` deployment key, so that you can test out the CodePush end-to-end.
44
106
 
45
- And that's it for installation using RNPM! Continue below to the [Plugin Configuration](#plugin-configuration-android) section to complete the setup.
107
+ And that's it for installation using RNPM! Continue below to the [Plugin Configuration](#plugin-configuration-for-react-native-lower-than-060-android) section to complete the setup.
46
108
 
47
109
  #### Plugin Installation (Android - Manual)
48
110
 
@@ -72,13 +134,13 @@ And that's it for installation using RNPM! Continue below to the [Plugin Configu
72
134
  ...
73
135
  ```
74
136
 
75
- ### Plugin Configuration (Android)
137
+ ### Plugin Configuration for React Native lower than 0.60 (Android)
76
138
 
77
139
  *NOTE: If you used RNPM or `react-native link` to automatically link the plugin, these steps have already been done for you so you may skip this section.*
78
140
 
79
141
  After installing the plugin and syncing your Android Studio project with Gradle, you need to configure your app to consult CodePush for the location of your JS bundle, since it will "take control" of managing the current and all future versions. To do this:
80
142
 
81
- #### For React Native >= v0.29
143
+ #### For React Native v0.29 - v0.59
82
144
 
83
145
  ##### For newly created React Native application
84
146
 
@@ -107,7 +169,7 @@ public class MainApplication extends Application implements ReactApplication {
107
169
  protected List<ReactPackage> getPackages() {
108
170
  // 3. Instantiate an instance of the CodePush runtime and add it to the list of
109
171
  // existing packages, specifying the right deployment key. If you don't already
110
- // have it, you can run "code-push deployment ls <appName> -k" to retrieve your key.
172
+ // have it, you can run "appcenter codepush deployment list -a <ownerName>/<appName> -k" to retrieve your key.
111
173
  return Arrays.<ReactPackage>asList(
112
174
  new MainReactPackage(),
113
175
  new CodePush("deployment-key-here", MainApplication.this, BuildConfig.DEBUG)
@@ -184,7 +246,7 @@ public class MainActivity extends ReactActivity {
184
246
  protected List<ReactPackage> getPackages() {
185
247
  // 3. Instantiate an instance of the CodePush runtime and add it to the list of
186
248
  // existing packages, specifying the right deployment key. If you don't already
187
- // have it, you can run "code-push deployment ls <appName> -k" to retrieve your key.
249
+ // have it, you can run "appcenter codepush deployment list -a <ownerName>/<appName> -k" to retrieve your key.
188
250
  return Arrays.<ReactPackage>asList(
189
251
  new MainReactPackage(),
190
252
  new CodePush("deployment-key-here", this, BuildConfig.DEBUG)
@@ -361,11 +423,11 @@ public class MainApplication extends NavigationApplication {
361
423
  }
362
424
  ```
363
425
 
364
- #### Code Signing setup
426
+ ### Code Signing setup
365
427
 
366
- Starting with CLI version **2.1.0** you can self sign bundles during release and verify its signature before installation of update. For more info about Code Signing please refer to [relevant code-push documentation section](https://github.com/Microsoft/code-push/tree/master/cli#code-signing). In order to use Public Key for Code Signing you need to do following steps:
428
+ Starting with CLI version **2.1.0** you can self sign bundles during release and verify its signature before installation of update. For more info about Code Signing please refer to [relevant code-push documentation section](https://github.com/microsoft/code-push/tree/v3.0.1/cli#code-signing). In order to use Public Key for Code Signing you need to do following steps:
367
429
 
368
- 1. Add `CodePushPublicKey` string item to `/path_to_your_app/android/app/src/main/res/values/strings.xml`. It may looks like this:
430
+ Add `CodePushPublicKey` string item to `/path_to_your_app/android/app/src/main/res/values/strings.xml`. It may looks like this:
369
431
 
370
432
  ```xml
371
433
  <resources>
@@ -382,9 +444,9 @@ zwIDAQAB
382
444
  </resources>
383
445
  ```
384
446
 
385
- 2. Configure `CodePush` instance to use this parameter
447
+ #### For React Native <= v0.60 you should configure the `CodePush` instance to use this parameter using one of the following approaches
386
448
 
387
- * using constructor
449
+ ##### Using constructor
388
450
 
389
451
  ```java
390
452
  new CodePush(
@@ -394,9 +456,7 @@ new CodePush(
394
456
  R.string.CodePushPublicKey)
395
457
  ```
396
458
 
397
- or
398
-
399
- * using builder
459
+ ##### Using builder
400
460
 
401
461
  ```java
402
462
  new CodePushBuilder("deployment-key-here",getApplicationContext())
package/docs/setup-ios.md CHANGED
@@ -1,8 +1,58 @@
1
1
  ## iOS Setup
2
2
 
3
3
  Once you've acquired the CodePush plugin, you need to integrate it into the Xcode project of your React Native app and configure it correctly. To do this, take the following steps:
4
+
5
+ ### Plugin Installation and Configuration for React Native 0.60 version and above (iOS)
4
6
 
5
- ### Plugin Installation (iOS)
7
+ 1. Run `cd ios && pod install && cd ..` to install all the necessary CocoaPods dependencies.
8
+
9
+ 2. Open up the `AppDelegate.m` file, and add an import statement for the CodePush headers:
10
+
11
+ ```objective-c
12
+ #import <CodePush/CodePush.h>
13
+ ```
14
+
15
+ 3. Find the following line of code, which sets the source URL for bridge for production releases:
16
+
17
+ ```objective-c
18
+ return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
19
+ ```
20
+
21
+ 4. Replace it with this line:
22
+
23
+ ```objective-c
24
+ return [CodePush bundleURL];
25
+ ```
26
+ This change configures your app to always load the most recent version of your app's JS bundle. On the first launch, this will correspond to the file that was compiled with the app. However, after an update has been pushed via CodePush, this will return the location of the most recently installed update.
27
+
28
+ *NOTE: The `bundleURL` method assumes your app's JS bundle is named `main.jsbundle`. If you have configured your app to use a different file name, simply call the `bundleURLForResource:` method (which assumes you're using the `.jsbundle` extension) or `bundleURLForResource:withExtension:` method instead, in order to overwrite that default behavior*
29
+
30
+ Typically, you're only going to want to use CodePush to resolve your JS bundle location within release builds, and therefore, we recommend using the `DEBUG` pre-processor macro to dynamically switch between using the packager server and CodePush, depending on whether you are debugging or not. This will make it much simpler to ensure you get the right behavior you want in production, while still being able to use the Chrome Dev Tools, live reload, etc. at debug-time.
31
+
32
+ Your `sourceURLForBridge` method should look like this:
33
+
34
+ ```objective-c
35
+ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
36
+ {
37
+ #if DEBUG
38
+ return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
39
+ #else
40
+ return [CodePush bundleURL];
41
+ #endif
42
+ }
43
+ ```
44
+
45
+ 5. Add the Deployment key to `Info.plist`:
46
+
47
+ To let the CodePush runtime know which deployment it should query for updates against, open your app's `Info.plist` file and add a new entry named `CodePushDeploymentKey`, whose value is the key of the deployment you want to configure this app against (like the key for the `Staging` deployment for the `FooBar` app). You can retrieve this value by running `appcenter codepush deployment list -a <ownerName>/<appName> -k` in the AppCenter CLI (the `-k` flag is necessary since keys aren't displayed by default) and copying the value of the `Key` column which corresponds to the deployment you want to use (see below). Note that using the deployment's name (like Staging) will not work. That "friendly name" is intended only for authenticated management usage from the CLI, and not for public consumption within your app.
48
+
49
+ ![Deployment list](https://cloud.githubusercontent.com/assets/116461/11601733/13011d5e-9a8a-11e5-9ce2-b100498ffb34.png)
50
+
51
+ In order to effectively make use of the `Staging` and `Production` deployments that were created along with your CodePush app, refer to the [multi-deployment testing](../README.md#multi-deployment-testing) docs below before actually moving your app's usage of CodePush into production.
52
+
53
+ *Note: If you need to dynamically use a different deployment, you can also override your deployment key in JS code using [Code-Push options](./api-js.md#CodePushOptions)*
54
+
55
+ ### Plugin Installation for React Native lower than 0.60 (iOS)
6
56
 
7
57
  In order to accommodate as many developer preferences as possible, the CodePush plugin supports iOS installation via three mechanisms:
8
58
 
@@ -26,7 +76,7 @@ In order to accommodate as many developer preferences as possible, the CodePush
26
76
 
27
77
  *Note: If you don't already have RNPM installed, you can do so by simply running `npm i -g rnpm` and then executing the above command. If you already have RNPM installed, make sure you have v1.9.0+ in order to benefit from this one step install.*
28
78
 
29
- 2. You will be prompted for the deployment key you'd like to use. If you don't already have it, you can retrieve this value by running `code-push deployment ls <appName> -k`, or you can choose to ignore it (by simply hitting `<ENTER>`) and add it in later. To get started, we would recommend just using your `Staging` deployment key, so that you can test out the CodePush end-to-end.
79
+ 2. You will be prompted for the deployment key you'd like to use. If you don't already have it, you can retrieve this value by running `appcenter codepush deployment list -a <ownerName>/<appName> -k`, or you can choose to ignore it (by simply hitting `<ENTER>`) and add it in later. To get started, we would recommend just using your `Staging` deployment key, so that you can test out the CodePush end-to-end.
30
80
 
31
81
  And that's it! Isn't RNPM awesome? :)
32
82
 
@@ -85,7 +135,7 @@ And that's it! Isn't RNPM awesome? :)
85
135
  *Note: Alternatively, if you prefer, you can add the `-lz` flag to the `Other Linker Flags` field in the `Linking` section of the `Build Settings`.*
86
136
 
87
137
 
88
- ### Plugin Configuration (iOS)
138
+ ### Plugin Configuration for React Native lower than 0.60 (iOS)
89
139
 
90
140
  *NOTE: If you used RNPM or `react-native link` to automatically link the plugin, these steps have already been done for you so you may skip this section.*
91
141
 
@@ -97,7 +147,7 @@ Once your Xcode project has been setup to build/link the CodePush plugin, you ne
97
147
  #import <CodePush/CodePush.h>
98
148
  ```
99
149
 
100
- For React Native 0.59 and above:
150
+ For React Native 0.59 - 0.59.10:
101
151
 
102
152
  2. Find the following line of code, which sets the source URL for bridge for production releases:
103
153
 
@@ -131,7 +181,7 @@ This change configures your app to always load the most recent version of your a
131
181
 
132
182
  Typically, you're only going to want to use CodePush to resolve your JS bundle location within release builds, and therefore, we recommend using the `DEBUG` pre-processor macro to dynamically switch between using the packager server and CodePush, depending on whether you are debugging or not. This will make it much simpler to ensure you get the right behavior you want in production, while still being able to use the Chrome Dev Tools, live reload, etc. at debug-time.
133
183
 
134
- For React Native 0.59 and above:
184
+ For React Native 0.59 - 0.59.10:
135
185
 
136
186
  ```objective-c
137
187
  - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
@@ -168,7 +218,7 @@ NSURL *jsCodeLocation;
168
218
  #endif
169
219
  ```
170
220
 
171
- To let the CodePush runtime know which deployment it should query for updates against, open your app's `Info.plist` file and add a new entry named `CodePushDeploymentKey`, whose value is the key of the deployment you want to configure this app against (like the key for the `Staging` deployment for the `FooBar` app). You can retrieve this value by running `code-push deployment ls <appName> -k` in the CodePush CLI (the `-k` flag is necessary since keys aren't displayed by default) and copying the value of the `Deployment Key` column which corresponds to the deployment you want to use (see below). Note that using the deployment's name (like Staging) will not work. That "friendly name" is intended only for authenticated management usage from the CLI, and not for public consumption within your app.
221
+ To let the CodePush runtime know which deployment it should query for updates against, open your app's `Info.plist` file and add a new entry named `CodePushDeploymentKey`, whose value is the key of the deployment you want to configure this app against (like the key for the `Staging` deployment for the `FooBar` app). You can retrieve this value by running `appcenter codepush deployment list -a <ownerName>/<appName> -k` in the AppCenter CLI (the `-k` flag is necessary since keys aren't displayed by default) and copying the value of the `Key` column which corresponds to the deployment you want to use (see below). Note that using the deployment's name (like Staging) will not work. That "friendly name" is intended only for authenticated management usage from the CLI, and not for public consumption within your app.
172
222
 
173
223
  ![Deployment list](https://cloud.githubusercontent.com/assets/116461/11601733/13011d5e-9a8a-11e5-9ce2-b100498ffb34.png)
174
224
 
@@ -208,7 +258,7 @@ Before doing anything, please [read the docs][ats] first.
208
258
 
209
259
  ### Code Signing setup
210
260
 
211
- Starting with CLI version **2.1.0** you can self sign bundles during release and verify its signature before installation of update. For more info about Code Signing please refer to [relevant code-push documentation section](https://github.com/Microsoft/code-push/tree/master/cli#code-signing).
261
+ Starting with CLI version **2.1.0** you can self sign bundles during release and verify its signature before installation of update. For more info about Code Signing please refer to [relevant code-push documentation section](https://github.com/microsoft/code-push/tree/v3.0.1/cli#code-signing).
212
262
 
213
263
  In order to configure Public Key for bundle verification you need to add record in `Info.plist` with name `CodePushPublicKey` and string value of public key content. Example:
214
264
 
@@ -37,7 +37,7 @@ class MainReactNativeHost : ReactNativeHost
37
37
  // 3. Update the JavaScriptBundleFile property to initalize the CodePush runtime,
38
38
  // specifying the right deployment key, then use it to return the bundle URL from
39
39
  // CodePush instead of statically from the binary. If you don't already have your
40
- // deployment key, you can run "code-push deployment ls <appName> -k" to retrieve it.
40
+ // deployment key, you can run "appcenter codepush deployment list -a <ownerName>/<appName> -k" to retrieve it.
41
41
  protected override string JavaScriptBundleFile
42
42
  {
43
43
  get
File without changes
@@ -31,6 +31,10 @@
31
31
  long long _latestExpectedContentLength;
32
32
  long long _latestReceivedConentLength;
33
33
  BOOL _didUpdateProgress;
34
+
35
+ BOOL _allowed;
36
+ BOOL _restartInProgress;
37
+ NSMutableArray *_restartQueue;
34
38
  }
35
39
 
36
40
  RCT_EXPORT_MODULE()
@@ -369,8 +373,11 @@ static NSString *const LatestRollbackCountKey = @"count";
369
373
 
370
374
  - (instancetype)init
371
375
  {
376
+ _allowed = YES;
377
+ _restartInProgress = NO;
378
+ _restartQueue = [NSMutableArray arrayWithCapacity:1];
379
+
372
380
  self = [super init];
373
-
374
381
  if (self) {
375
382
  [self initializeUpdateAfterRestart];
376
383
  }
@@ -636,25 +643,41 @@ static NSString *const LatestRollbackCountKey = @"count";
636
643
  return @[DownloadProgressEvent];
637
644
  }
638
645
 
646
+ // Determine how long the app was in the background
647
+ - (int)getDurationInBackground
648
+ {
649
+ int duration = 0;
650
+ if (_lastResignedDate) {
651
+ duration = [[NSDate date] timeIntervalSinceDate:_lastResignedDate];
652
+ }
653
+
654
+ return duration;
655
+ }
656
+
639
657
  #pragma mark - Application lifecycle event handlers
640
658
 
641
- // These two handlers will only be registered when there is
659
+ // These three handlers will only be registered when there is
642
660
  // a resume-based update still pending installation.
643
- - (void)applicationWillEnterForeground
661
+ - (void)applicationDidBecomeActive
644
662
  {
645
- if (_appSuspendTimer) {
646
- [_appSuspendTimer invalidate];
647
- _appSuspendTimer = nil;
648
- }
649
- // Determine how long the app was in the background and ensure
650
- // that it meets the minimum duration amount of time.
651
- int durationInBackground = 0;
652
- if (_lastResignedDate) {
653
- durationInBackground = [[NSDate date] timeIntervalSinceDate:_lastResignedDate];
663
+ if (_installMode == CodePushInstallModeOnNextSuspend) {
664
+ int durationInBackground = [self getDurationInBackground];
665
+ // We shouldn't use loadBundle in this case, because _appSuspendTimer will call loadBundleOnTick.
666
+ // We should cancel timer for _appSuspendTimer because otherwise, we would call loadBundle two times.
667
+ if (durationInBackground < _minimumBackgroundDuration) {
668
+ [_appSuspendTimer invalidate];
669
+ _appSuspendTimer = nil;
670
+ }
654
671
  }
672
+ }
655
673
 
656
- if (durationInBackground >= _minimumBackgroundDuration) {
657
- [self loadBundle];
674
+ - (void)applicationWillEnterForeground
675
+ {
676
+ if (_installMode == CodePushInstallModeOnNextResume) {
677
+ int durationInBackground = [self getDurationInBackground];
678
+ if (durationInBackground >= _minimumBackgroundDuration) {
679
+ [self restartAppInternal:NO];
680
+ }
658
681
  }
659
682
  }
660
683
 
@@ -674,7 +697,7 @@ static NSString *const LatestRollbackCountKey = @"count";
674
697
  }
675
698
 
676
699
  -(void)loadBundleOnTick:(NSTimer *)timer {
677
- [self loadBundle];
700
+ [self restartAppInternal:NO];
678
701
  }
679
702
 
680
703
  #pragma mark - JavaScript-exported module methods (Public)
@@ -746,6 +769,33 @@ RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage
746
769
  }];
747
770
  }
748
771
 
772
+ - (void)restartAppInternal:(BOOL)onlyIfUpdateIsPending
773
+ {
774
+ if (_restartInProgress) {
775
+ CPLog(@"Restart request queued until the current restart is completed.");
776
+ [_restartQueue addObject:@(onlyIfUpdateIsPending)];
777
+ return;
778
+ } else if (!_allowed) {
779
+ CPLog(@"Restart request queued until restarts are re-allowed.");
780
+ [_restartQueue addObject:@(onlyIfUpdateIsPending)];
781
+ return;
782
+ }
783
+
784
+ _restartInProgress = YES;
785
+ if (!onlyIfUpdateIsPending || [[self class] isPendingUpdate:nil]) {
786
+ [self loadBundle];
787
+ CPLog(@"Restarting app.");
788
+ return;
789
+ }
790
+
791
+ _restartInProgress = NO;
792
+ if ([_restartQueue count] > 0) {
793
+ BOOL buf = [_restartQueue valueForKey: @"@firstObject"];
794
+ [_restartQueue removeObjectAtIndex:0];
795
+ [self restartAppInternal:buf];
796
+ }
797
+ }
798
+
749
799
  /*
750
800
  * This is the native side of the CodePush.getConfiguration method. It isn't
751
801
  * currently exposed via the "react-native-code-push" module, and is used
@@ -859,6 +909,11 @@ RCT_EXPORT_METHOD(installUpdate:(NSDictionary*)updatePackage
859
909
  // Ensure we do not add the listener twice.
860
910
  // Register for app resume notifications so that we
861
911
  // can check for pending updates which support "restart on resume"
912
+ [[NSNotificationCenter defaultCenter] addObserver:self
913
+ selector:@selector(applicationDidBecomeActive)
914
+ name:UIApplicationDidBecomeActiveNotification
915
+ object:RCTSharedApplication()];
916
+
862
917
  [[NSNotificationCenter defaultCenter] addObserver:self
863
918
  selector:@selector(applicationWillEnterForeground)
864
919
  name:UIApplicationWillEnterForegroundNotification
@@ -895,6 +950,7 @@ RCT_EXPORT_METHOD(setLatestRollbackInfo:(NSString *)packageHash
895
950
  reject:(RCTPromiseRejectBlock)reject)
896
951
  {
897
952
  [[self class] setLatestRollbackInfo:packageHash];
953
+ resolve(nil);
898
954
  }
899
955
 
900
956
 
@@ -932,6 +988,37 @@ RCT_EXPORT_METHOD(notifyApplicationReady:(RCTPromiseResolveBlock)resolve
932
988
  resolve(nil);
933
989
  }
934
990
 
991
+ RCT_EXPORT_METHOD(allow:(RCTPromiseResolveBlock)resolve
992
+ rejecter:(RCTPromiseRejectBlock)reject)
993
+ {
994
+ CPLog(@"Re-allowing restarts.");
995
+ _allowed = YES;
996
+
997
+ if ([_restartQueue count] > 0) {
998
+ CPLog(@"Executing pending restart.");
999
+ BOOL buf = [_restartQueue valueForKey: @"@firstObject"];
1000
+ [_restartQueue removeObjectAtIndex:0];
1001
+ [self restartAppInternal:buf];
1002
+ }
1003
+
1004
+ resolve(nil);
1005
+ }
1006
+
1007
+ RCT_EXPORT_METHOD(clearPendingRestart:(RCTPromiseResolveBlock)resolve
1008
+ rejecter:(RCTPromiseRejectBlock)reject)
1009
+ {
1010
+ [_restartQueue removeAllObjects];
1011
+ resolve(nil);
1012
+ }
1013
+
1014
+ RCT_EXPORT_METHOD(disallow:(RCTPromiseResolveBlock)resolve
1015
+ rejecter:(RCTPromiseRejectBlock)reject)
1016
+ {
1017
+ CPLog(@"Disallowing restarts.");
1018
+ _allowed = NO;
1019
+ resolve(nil);
1020
+ }
1021
+
935
1022
  /*
936
1023
  * This method is the native side of the CodePush.restartApp() method.
937
1024
  */
@@ -939,15 +1026,8 @@ RCT_EXPORT_METHOD(restartApp:(BOOL)onlyIfUpdateIsPending
939
1026
  resolve:(RCTPromiseResolveBlock)resolve
940
1027
  rejecter:(RCTPromiseRejectBlock)reject)
941
1028
  {
942
- // If this is an unconditional restart request, or there
943
- // is current pending update, then reload the app.
944
- if (!onlyIfUpdateIsPending || [[self class] isPendingUpdate:nil]) {
945
- [self loadBundle];
946
- resolve(@(YES));
947
- return;
948
- }
949
-
950
- resolve(@(NO));
1029
+ [self restartAppInternal:onlyIfUpdateIsPending];
1030
+ resolve(nil);
951
1031
  }
952
1032
 
953
1033
  /*
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes