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

Commit 1a1004e

Browse files
author
Richard Hua
committed
Allow the binary version to be specified independently of the app version
1 parent 12efdb0 commit 1a1004e

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class CodePush implements ReactPackage {
2929
private static boolean sIsRunningBinaryVersion = false;
3030
private static boolean sNeedToReportRollback = false;
3131
private static boolean sTestConfigurationFlag = false;
32+
private static String sAppVersionOverride = null;
3233

3334
private boolean mDidUpdate = false;
3435

@@ -40,7 +41,7 @@ public class CodePush implements ReactPackage {
4041
private SettingsManager mSettingsManager;
4142

4243
// Config properties.
43-
private String mAppVersion;
44+
private String mPListAppVersion;
4445
private String mDeploymentKey;
4546
private String mServerUrl = "https://codepush.azurewebsites.net/";
4647

@@ -65,7 +66,7 @@ public CodePush(String deploymentKey, Context context, boolean isDebugMode) {
6566

6667
try {
6768
PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
68-
mAppVersion = pInfo.versionName;
69+
mPListAppVersion = pInfo.versionName;
6970
} catch (PackageManager.NameNotFoundException e) {
7071
throw new CodePushUnknownException("Unable to get package info for " + mContext.getPackageName(), e);
7172
}
@@ -96,7 +97,7 @@ public boolean didUpdate() {
9697
}
9798

9899
public String getAppVersion() {
99-
return mAppVersion;
100+
return sAppVersionOverride == null ? mPListAppVersion : sAppVersionOverride;
100101
}
101102

102103
public String getAssetsBundleFileName() {
@@ -177,14 +178,14 @@ public String getJSBundleFileInternal(String assetsBundleFileName) {
177178
String packageAppVersion = CodePushUtils.tryGetString(packageMetadata, "appVersion");
178179
if (binaryModifiedDateDuringPackageInstall != null &&
179180
binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
180-
(isUsingTestConfiguration() || this.mAppVersion.equals(packageAppVersion))) {
181+
(isUsingTestConfiguration() || this.getAppVersion().equals(packageAppVersion))) {
181182
CodePushUtils.logBundleUrl(packageFilePath);
182183
sIsRunningBinaryVersion = false;
183184
return packageFilePath;
184185
} else {
185186
// The binary version is newer.
186187
this.mDidUpdate = false;
187-
if (!this.mIsDebugMode || !this.mAppVersion.equals(packageAppVersion)) {
188+
if (!this.mIsDebugMode || !this.getAppVersion().equals(packageAppVersion)) {
188189
this.clearUpdates();
189190
}
190191

@@ -249,6 +250,10 @@ boolean needToReportRollback() {
249250
return sNeedToReportRollback;
250251
}
251252

253+
public static void overrideAppVersion(String appVersionOverride) {
254+
sAppVersionOverride = appVersionOverride;
255+
}
256+
252257
private void rollbackPackage() {
253258
WritableMap failedPackage = mUpdateManager.getCurrentPackage();
254259
mSettingsManager.saveFailedUpdate(failedPackage);
@@ -280,7 +285,7 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactAppli
280285
CodePushNativeModule codePushModule = new CodePushNativeModule(reactApplicationContext, this, mUpdateManager, mTelemetryManager, mSettingsManager);
281286
CodePushDialog dialogModule = new CodePushDialog(reactApplicationContext);
282287

283-
List<NativeModule> nativeModules = new ArrayList<>();
288+
List<NativeModule> nativeModules = new ArrayList<>();
284289
nativeModules.add(codePushModule);
285290
nativeModules.add(dialogModule);
286291
return nativeModules;

ios/CodePush/CodePush.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@
3030
+ (NSString *)bundleAssetsPath;
3131

3232
/*
33-
* This methods allows dynamically setting the app's
33+
* This method allows the version of the app's binary interface
34+
* to be specified, which would otherwise default to the
35+
* App Store version of the app.
36+
*/
37+
+ (void)overrideAppVersion:(NSString *)deploymentKey;
38+
39+
/*
40+
* This method allows dynamically setting the app's
3441
* deployment key, in addition to setting it via
3542
* the Info.plist file's CodePushDeploymentKey setting.
3643
*/
@@ -45,7 +52,7 @@
4552

4653
@interface CodePushConfig : NSObject
4754

48-
@property (readonly) NSString *appVersion;
55+
@property (copy) NSString *appVersion;
4956
@property (readonly) NSString *buildVersion;
5057
@property (readonly) NSDictionary *configuration;
5158
@property (copy) NSString *deploymentKey;

ios/CodePush/CodePush.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ + (NSString *)bundleAssetsPath
7373
if (bundleResourceSubdirectory) {
7474
resourcePath = [resourcePath stringByAppendingPathComponent:bundleResourceSubdirectory];
7575
}
76-
76+
7777
return [resourcePath stringByAppendingPathComponent:[CodePushUpdateUtils assetsFolderName]];
7878
}
7979

@@ -159,6 +159,11 @@ + (NSString *)getApplicationSupportDirectory
159159
return applicationSupportDirectory;
160160
}
161161

162+
+ (void)overrideAppVersion:(NSString *)appVersion
163+
{
164+
[CodePushConfig current].appVersion = appVersion;
165+
}
166+
162167
+ (void)setDeploymentKey:(NSString *)deploymentKey
163168
{
164169
[CodePushConfig current].deploymentKey = deploymentKey;

ios/CodePush/CodePushConfig.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ - (NSString *)clientUniqueId
8686
return [_configDictionary objectForKey:ClientUniqueIDConfigKey];
8787
}
8888

89+
- (void)setAppVersion:(NSString *)appVersion
90+
{
91+
[_configDictionary setValue:appVersion forKey:AppVersionConfigKey];
92+
}
93+
8994
- (void)setDeploymentKey:(NSString *)deploymentKey
9095
{
9196
[_configDictionary setValue:deploymentKey forKey:DeploymentKeyConfigKey];

0 commit comments

Comments
 (0)