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

Commit 7d15a58

Browse files
committed
Merge pull request #165 from Microsoft/dynamic_key
[CodePush setDeploymentKey] method
2 parents d388ad2 + 960a75b commit 7d15a58

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
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: 24 additions & 17 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;
@@ -38,9 +40,8 @@ @implementation CodePush {
3840
static NSString *const PackageHashKey = @"packageHash";
3941
static NSString *const PackageIsPendingKey = @"isPending";
4042

41-
@synthesize bridge = _bridge;
43+
#pragma mark - Public Obj-C API
4244

43-
// Public Obj-C API (see header for method comments)
4445
+ (NSURL *)bundleURL
4546
{
4647
return [self bundleURLForResource:@"main"];
@@ -91,7 +92,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
9192
#ifndef DEBUG
9293
[CodePush clearUpdates];
9394
#endif
94-
95+
9596
NSLog(logMessageFormat, binaryJsBundleUrl);
9697
isRunningBinaryVersion = YES;
9798
return binaryJsBundleUrl;
@@ -113,7 +114,12 @@ + (BOOL)isUsingTestConfiguration
113114
return testConfigurationFlag;
114115
}
115116

116-
/*
117+
+ (void)setDeploymentKey:(NSString *)deploymentKey
118+
{
119+
[CodePushConfig current].deploymentKey = deploymentKey;
120+
}
121+
122+
/*
117123
* This is used to enable an environment in which tests can be run.
118124
* Specifically, it flips a boolean flag that causes bundles to be
119125
* saved to a test folder and enables the ability to modify
@@ -134,8 +140,9 @@ + (void)clearUpdates
134140
[self removeFailedUpdates];
135141
}
136142

143+
#pragma mark - Private API methods
137144

138-
// Private API methods
145+
@synthesize bridge = _bridge;
139146

140147
/*
141148
* This method is used by the React Native bridge to allow
@@ -147,10 +154,10 @@ - (NSDictionary *)constantsToExport
147154
{
148155
// Export the values of the CodePushInstallMode enum
149156
// so that the script-side can easily stay in sync
150-
return @{
151-
@"codePushInstallModeOnNextRestart":@(CodePushInstallModeOnNextRestart),
152-
@"codePushInstallModeImmediate": @(CodePushInstallModeImmediate),
153-
@"codePushInstallModeOnNextResume": @(CodePushInstallModeOnNextResume)
157+
return @{
158+
@"codePushInstallModeOnNextRestart":@(CodePushInstallModeOnNextRestart),
159+
@"codePushInstallModeImmediate": @(CodePushInstallModeImmediate),
160+
@"codePushInstallModeOnNextResume": @(CodePushInstallModeOnNextResume)
154161
};
155162
};
156163

@@ -257,7 +264,7 @@ - (BOOL)isPendingUpdate:(NSString*)packageHash
257264
{
258265
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
259266
NSDictionary *pendingUpdate = [preferences objectForKey:PendingUpdateKey];
260-
267+
261268
// If there is a pending update whose "state" isn't loading, then we consider it "pending".
262269
// Additionally, if a specific hash was provided, we ensure it matches that of the pending update.
263270
BOOL updateIsPending = pendingUpdate &&
@@ -380,7 +387,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
380387
[preferences synchronize];
381388
}
382389

383-
// JavaScript-exported module methods
390+
#pragma mark - JavaScript-exported module methods
384391

385392
/*
386393
* This is native-side of the RemotePackage.download method
@@ -404,11 +411,11 @@ - (void)savePendingUpdate:(NSString *)packageHash
404411
doneCallback:^{
405412
NSError *err;
406413
NSDictionary *newPackage = [CodePushPackage getPackage:updatePackage[PackageHashKey] error:&err];
407-
414+
408415
if (err) {
409416
return reject(err);
410417
}
411-
418+
412419
resolve(newPackage);
413420
}
414421
// The download failed
@@ -447,7 +454,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
447454
// the script-side doesn't need to immediately call back into native to populate it.
448455
BOOL isPendingUpdate = [self isPendingUpdate:[package objectForKey:PackageHashKey]];
449456
[package setObject:@(isPendingUpdate) forKey:PackageIsPendingKey];
450-
457+
451458
resolve(package);
452459
});
453460
}
@@ -527,7 +534,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
527534
}
528535

529536
/*
530-
* This method is checks if a new status update exists (new version was installed,
537+
* This method is checks if a new status update exists (new version was installed,
531538
* or an update failed) and return its details (version label, status).
532539
*/
533540
RCT_EXPORT_METHOD(getNewStatusReport:(RCTPromiseResolveBlock)resolve
@@ -589,7 +596,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
589596
/*
590597
* This method is the native side of the CodePush.downloadAndReplaceCurrentBundle()
591598
* method, which replaces the current bundle with the one downloaded from
592-
* removeBundleUrl. It is only to be used during tests and no-ops if the test
599+
* removeBundleUrl. It is only to be used during tests and no-ops if the test
593600
* configuration flag is not set.
594601
*/
595602
RCT_EXPORT_METHOD(downloadAndReplaceCurrentBundle:(NSString *)remoteBundleUrl)
@@ -599,4 +606,4 @@ - (void)savePendingUpdate:(NSString *)packageHash
599606
}
600607
}
601608

602-
@end
609+
@end

0 commit comments

Comments
 (0)