Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 9d9b664

Browse files
committed
update to master
2 parents 0712451 + 7d9162d commit 9d9b664

File tree

4 files changed

+51
-37
lines changed

4 files changed

+51
-37
lines changed

CodePush.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* This method assumes that your JS bundle is named "main.jsbundle"
1313
* and therefore, if it isn't, you should use either the bundleURLForResource:
1414
* or bundleURLForResource:withExtension: methods to override that behavior.
15-
*/
15+
*/
1616
+ (NSURL *)bundleURL;
1717

1818
+ (NSURL *)bundleURLForResource:(NSString *)resourceName;
@@ -22,6 +22,13 @@
2222

2323
+ (NSString *)getApplicationSupportDirectory;
2424

25+
/*
26+
* This methods allows dynamically setting the app's
27+
* deployment key, in addition to setting it via
28+
* the Info.plist file's CodePushDeploymentKey setting.
29+
*/
30+
+ (void)setDeploymentKey:(NSString *)deploymentKey;
31+
2532
// The below methods are only used during tests.
2633
+ (BOOL)isUsingTestConfiguration;
2734
+ (void)setUsingTestConfiguration:(BOOL)shouldUseTestConfiguration;
@@ -62,7 +69,7 @@ failCallback:(void (^)(NSError *err))failCallback;
6269
@interface CodePushPackage : NSObject
6370

6471
+ (void)installPackage:(NSDictionary *)updatePackage
65-
error:(NSError **)error;
72+
error:(NSError **)error;
6673

6774
+ (NSDictionary *)getCurrentPackage:(NSError **)error;
6875
+ (NSString *)getCurrentPackageFolderPath:(NSError **)error;

CodePush.m

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ @implementation CodePush {
1313

1414
RCT_EXPORT_MODULE()
1515

16+
#pragma mark - Private constants
17+
1618
static BOOL needToReportRollback = NO;
1719
static BOOL isRunningBinaryVersion = NO;
1820
static BOOL testConfigurationFlag = NO;
@@ -35,9 +37,8 @@ @implementation CodePush {
3537
static NSString *const PackageHashKey = @"packageHash";
3638
static NSString *const PackageIsPendingKey = @"isPending";
3739

38-
@synthesize bridge = _bridge;
40+
#pragma mark - Public Obj-C API
3941

40-
// Public Obj-C API (see header for method comments)
4142
+ (NSURL *)bundleURL
4243
{
4344
return [self bundleURLForResource:@"main"];
@@ -88,7 +89,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
8889
#ifndef DEBUG
8990
[CodePush clearUpdates];
9091
#endif
91-
92+
9293
NSLog(logMessageFormat, binaryJsBundleUrl);
9394
isRunningBinaryVersion = YES;
9495
return binaryJsBundleUrl;
@@ -110,7 +111,12 @@ + (BOOL)isUsingTestConfiguration
110111
return testConfigurationFlag;
111112
}
112113

113-
/*
114+
+ (void)setDeploymentKey:(NSString *)deploymentKey
115+
{
116+
[CodePushConfig current].deploymentKey = deploymentKey;
117+
}
118+
119+
/*
114120
* This is used to enable an environment in which tests can be run.
115121
* Specifically, it flips a boolean flag that causes bundles to be
116122
* saved to a test folder and enables the ability to modify
@@ -131,8 +137,9 @@ + (void)clearUpdates
131137
[self removeFailedUpdates];
132138
}
133139

140+
#pragma mark - Private API methods
134141

135-
// Private API methods
142+
@synthesize bridge = _bridge;
136143

137144
/*
138145
* This method is used by the React Native bridge to allow
@@ -144,10 +151,10 @@ - (NSDictionary *)constantsToExport
144151
{
145152
// Export the values of the CodePushInstallMode enum
146153
// so that the script-side can easily stay in sync
147-
return @{
148-
@"codePushInstallModeOnNextRestart":@(CodePushInstallModeOnNextRestart),
149-
@"codePushInstallModeImmediate": @(CodePushInstallModeImmediate),
150-
@"codePushInstallModeOnNextResume": @(CodePushInstallModeOnNextResume)
154+
return @{
155+
@"codePushInstallModeOnNextRestart":@(CodePushInstallModeOnNextRestart),
156+
@"codePushInstallModeImmediate": @(CodePushInstallModeImmediate),
157+
@"codePushInstallModeOnNextResume": @(CodePushInstallModeOnNextResume)
151158
};
152159
};
153160

@@ -234,7 +241,7 @@ - (BOOL)isPendingUpdate:(NSString*)packageHash
234241
{
235242
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
236243
NSDictionary *pendingUpdate = [preferences objectForKey:PendingUpdateKey];
237-
244+
238245
// If there is a pending update whose "state" isn't loading, then we consider it "pending".
239246
// Additionally, if a specific hash was provided, we ensure it matches that of the pending update.
240247
BOOL updateIsPending = pendingUpdate &&
@@ -350,7 +357,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
350357
[preferences synchronize];
351358
}
352359

353-
// JavaScript-exported module methods
360+
#pragma mark - JavaScript-exported module methods
354361

355362
/*
356363
* This is native-side of the RemotePackage.download method
@@ -419,7 +426,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
419426
// the script-side doesn't need to immediately call back into native to populate it.
420427
BOOL isPendingUpdate = [self isPendingUpdate:[package objectForKey:PackageHashKey]];
421428
[package setObject:@(isPendingUpdate) forKey:PackageIsPendingKey];
422-
429+
423430
resolve(package);
424431
});
425432
}
@@ -551,7 +558,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
551558
/*
552559
* This method is the native side of the CodePush.downloadAndReplaceCurrentBundle()
553560
* method, which replaces the current bundle with the one downloaded from
554-
* removeBundleUrl. It is only to be used during tests and no-ops if the test
561+
* removeBundleUrl. It is only to be used during tests and no-ops if the test
555562
* configuration flag is not set.
556563
*/
557564
RCT_EXPORT_METHOD(downloadAndReplaceCurrentBundle:(NSString *)remoteBundleUrl)
@@ -561,4 +568,4 @@ - (void)savePendingUpdate:(NSString *)packageHash
561568
}
562569
}
563570

564-
@end
571+
@end

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ The simplest way to do this is to perform the following in your app's root compo
266266
1. Import the JavaScript module for CodePush:
267267
268268
```javascript
269-
import CodePush from "react-native-code-push";
269+
import codePush from "react-native-code-push";
270270
```
271271
272272
2. Call the `sync` method from within the `componentDidMount` lifecycle event, to initiate a background update on each app start:
273273
274274
```javascript
275-
CodePush.sync();
275+
codePush.sync();
276276
```
277277
278278
If an update is available, it will be silently downloaded, and installed the next time the app is restarted (either explicitly by the end user or by the OS), which ensures the least invasive experience for your end users. If you would like to display a confirmation dialog (an "active install"), or customize the update experience in any way, refer to the `sync` method's [API reference](#codepushsync) for information on how to tweak this default behavior.
@@ -467,7 +467,7 @@ While the `sync` method tries to make it easy to perform silent and active updat
467467
468468
* __deploymentKey__ *(String)* - Specifies the deployment key you want to query for an update against. By default, this value is derived from the `Info.plist` file (iOS) and `MainActivity.java` file (Android), but this option allows you to override it from the script-side if you need to dynamically use a different deployment for a specific call to `sync`.
469469
470-
* __installMode__ *(CodePush.InstallMode)* - Indicates when you would like to "install" the update after downloading it, which includes reloading the JS bundle in order for any changes to take affect. Defaults to `CodePush.InstallMode.ON_NEXT_RESTART`. Refer to the [`InstallMode`](#installmode) enum reference for a description of the available options and what they do.
470+
* __installMode__ *(codePush.InstallMode)* - Indicates when you would like to "install" the update after downloading it, which includes reloading the JS bundle in order for any changes to take affect. Defaults to `codePush.InstallMode.ON_NEXT_RESTART`. Refer to the [`InstallMode`](#installmode) enum reference for a description of the available options and what they do.
471471
472472
* __updateDialog__ *(UpdateDialogOptions)* - An "options" object used to determine whether a confirmation dialog should be displayed to the end user when an update is available, and if so, what strings to use. Defaults to `null`, which has the effect of disabling the dialog completely. Setting this to any truthy value will enable the dialog with the default strings, and passing an object to this parameter allows enabling the dialog as well as overriding one or more of the default strings. The following list represents the available options and their defaults:
473473
* __appendReleaseDescription__ *(Boolean)* - Indicates whether you would like to append the description of an available release to the notification message which is displayed to the end user. Defaults to `false`.
@@ -529,10 +529,10 @@ Example Usage:
529529
// and then display a "downloading" modal
530530
codePush.sync({ updateDialog: true }, (status) => {
531531
switch (status) {
532-
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
532+
case codePush.SyncStatus.DOWNLOADING_PACKAGE:
533533
// Show "downloading" modal
534534
break;
535-
case CodePush.SyncStatus.INSTALLING_UPDATE:
535+
case codePush.SyncStatus.INSTALLING_UPDATE:
536536
// Hide "downloading" modal
537537
break;
538538
}
@@ -541,11 +541,11 @@ codePush.sync({ updateDialog: true }, (status) => {
541541
542542
This method returns a `Promise` which is resolved to a `SyncStatus` code that indicates why the `sync` call succeeded. This code can be one of the following `SyncStatus` values:
543543
544-
* __CodePush.SyncStatus.UP_TO_DATE__ *(4)* - The app is up-to-date with the CodePush server.
544+
* __codePush.SyncStatus.UP_TO_DATE__ *(4)* - The app is up-to-date with the CodePush server.
545545
546-
* __CodePush.SyncStatus.UPDATE_IGNORED__ *(5)* - The app had an optional update which the end user chose to ignore. (This is only applicable when the `updateDialog` is used)
546+
* __codePush.SyncStatus.UPDATE_IGNORED__ *(5)* - The app had an optional update which the end user chose to ignore. (This is only applicable when the `updateDialog` is used)
547547
548-
* __CodePush.SyncStatus.UPDATE_INSTALLED__ *(6)* - The update has been installed and will be run either immediately after the `syncStatusChangedCallback` function returns or the next time the app resumes/restarts, depending on the `InstallMode` specified in `SyncOptions`.
548+
* __codePush.SyncStatus.UPDATE_INSTALLED__ *(6)* - The update has been installed and will be run either immediately after the `syncStatusChangedCallback` function returns or the next time the app resumes/restarts, depending on the `InstallMode` specified in `SyncOptions`.
549549
550550
If the update check and/or the subsequent download fails for any reason, the `Promise` object returned by `sync` will be rejected with the reason.
551551
@@ -576,7 +576,7 @@ Contains details about an update that has been downloaded locally or already ins
576576
- __packageSize__: The size of the code contained within the update, in bytes. *(Number)*
577577
578578
###### Methods
579-
- __install(installMode: CodePush.InstallMode = CodePush.InstallMode.ON_NEXT_RESTART): Promise<void>__: Installs the update by saving it to the location on disk where the runtime expects to find the latest version of the app. The `installMode` parameter controls when the changes are actually presented to the end user. The default value is to wait until the next app restart to display the changes, but you can refer to the [`InstallMode`](#installmode) enum reference for a description of the available options and what they do.
579+
- __install(installMode: codePush.InstallMode = codePush.InstallMode.ON_NEXT_RESTART): Promise<void>__: Installs the update by saving it to the location on disk where the runtime expects to find the latest version of the app. The `installMode` parameter controls when the changes are actually presented to the end user. The default value is to wait until the next app restart to display the changes, but you can refer to the [`InstallMode`](#installmode) enum reference for a description of the available options and what they do.
580580
581581
##### RemotePackage
582582
@@ -598,24 +598,24 @@ The CodePush API includes the following enums which can be used to customize the
598598
##### InstallMode
599599
600600
This enum specified when you would like an installed update to actually be applied, and can be passed to either the `sync` or `LocalPackage.install` methods. It includes the following values:
601-
* __CodePush.InstallMode.IMMEDIATE__ *(0)* - Indicates that you want to install the update and restart the app immediately. This value is appropriate for debugging scenarios as well as when displaying an update prompt to the user, since they would expect to see the changes immediately after accepting the installation.
601+
* __codePush.InstallMode.IMMEDIATE__ *(0)* - Indicates that you want to install the update and restart the app immediately. This value is appropriate for debugging scenarios as well as when displaying an update prompt to the user, since they would expect to see the changes immediately after accepting the installation.
602602
603-
* __CodePush.InstallMode.ON_NEXT_RESTART__ *(1)* - Indicates that you want to install the update, but not forcibly restart the app. When the app is "naturally" restarted (due the OS or end user killing it), the update will be seamlessly picked up. This value is appropriate when performing silent updates, since it would likely be disruptive to the end user if the app suddenly restarted out of nowhere, since they wouldn't have realized an update was even downloaded. This is the default mode used for both the `sync` and `LocalPackage.install` methods.
603+
* __codePush.InstallMode.ON_NEXT_RESTART__ *(1)* - Indicates that you want to install the update, but not forcibly restart the app. When the app is "naturally" restarted (due the OS or end user killing it), the update will be seamlessly picked up. This value is appropriate when performing silent updates, since it would likely be disruptive to the end user if the app suddenly restarted out of nowhere, since they wouldn't have realized an update was even downloaded. This is the default mode used for both the `sync` and `LocalPackage.install` methods.
604604
605-
* __CodePush.InstallMode.ON_NEXT_RESUME__ *(2)* - Indicates that you want to install the update, but don't want to restart the app until the next time the end user resumes it from the background. This way, you don't disrupt their current session, but you can get the update in front of them sooner then having to wait for the next natural restart. This value is appropriate for silent installs that can be applied on resume in a non-invasive way.
605+
* __codePush.InstallMode.ON_NEXT_RESUME__ *(2)* - Indicates that you want to install the update, but don't want to restart the app until the next time the end user resumes it from the background. This way, you don't disrupt their current session, but you can get the update in front of them sooner then having to wait for the next natural restart. This value is appropriate for silent installs that can be applied on resume in a non-invasive way.
606606
607607
##### SyncStatus
608608
609609
This enum is provided to the `syncStatusChangedCallback` function that can be passed to the `sync` method, in order to hook into the overall update process. It includes the following values:
610610
611-
* __CodePush.SyncStatus.CHECKING_FOR_UPDATE__ *(0)* - The CodePush server is being queried for an update.
612-
* __CodePush.SyncStatus.AWAITING_USER_ACTION__ *(1)* - An update is available, and a confirmation dialog was shown to the end user. (This is only applicable when the `updateDialog` is used)
613-
* __CodePush.SyncStatus.DOWNLOADING_PACKAGE__ *(2)* - An available update is being downloaded from the CodePush server.
614-
* __CodePush.SyncStatus.INSTALLING_UPDATE__ *(3)* - An available update was downloaded and is about to be installed.
615-
* __CodePush.SyncStatus.UP_TO_DATE__ *(4)* - The app is fully up-to-date with the configured deployment.
616-
* __CodePush.SyncStatus.UPDATE_IGNORED__ *(5)* - The app has an optional update, which the end user chose to ignore. (This is only applicable when the `updateDialog` is used)
617-
* __CodePush.SyncStatus.UPDATE_INSTALLED__ *(6)* - An available update has been installed and will be run either immediately after the `syncStatusChangedCallback` function returns or the next time the app resumes/restarts, depending on the `InstallMode` specified in `SyncOptions`.
618-
* __CodePush.SyncStatus.UNKNOWN_ERROR__ *(-1)* - The sync operation encountered an unknown error.
611+
* __codePush.SyncStatus.CHECKING_FOR_UPDATE__ *(0)* - The CodePush server is being queried for an update.
612+
* __codePush.SyncStatus.AWAITING_USER_ACTION__ *(1)* - An update is available, and a confirmation dialog was shown to the end user. (This is only applicable when the `updateDialog` is used)
613+
* __codePush.SyncStatus.DOWNLOADING_PACKAGE__ *(2)* - An available update is being downloaded from the CodePush server.
614+
* __codePush.SyncStatus.INSTALLING_UPDATE__ *(3)* - An available update was downloaded and is about to be installed.
615+
* __codePush.SyncStatus.UP_TO_DATE__ *(4)* - The app is fully up-to-date with the configured deployment.
616+
* __codePush.SyncStatus.UPDATE_IGNORED__ *(5)* - The app has an optional update, which the end user chose to ignore. (This is only applicable when the `updateDialog` is used)
617+
* __codePush.SyncStatus.UPDATE_INSTALLED__ *(6)* - An available update has been installed and will be run either immediately after the `syncStatusChangedCallback` function returns or the next time the app resumes/restarts, depending on the `InstallMode` specified in `SyncOptions`.
618+
* __codePush.SyncStatus.UNKNOWN_ERROR__ *(-1)* - The sync operation encountered an unknown error.
619619
620620
### Objective-C API Reference (iOS)
621621

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-code-push",
3-
"version": "1.5.3-beta",
3+
"version": "1.6.0-beta",
44
"description": "React Native plugin for the CodePush service",
55
"main": "CodePush.js",
66
"homepage": "https://microsoft.github.io/code-push",

0 commit comments

Comments
 (0)