diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index 2c18009..6c166b4 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -29,6 +29,7 @@ public class CodePush implements ReactPackage { private static boolean sIsRunningBinaryVersion = false; private static boolean sNeedToReportRollback = false; private static boolean sTestConfigurationFlag = false; + private static String sAppVersionOverride = null; private boolean mDidUpdate = false; @@ -40,7 +41,7 @@ public class CodePush implements ReactPackage { private SettingsManager mSettingsManager; // Config properties. - private String mAppVersion; + private String mPListAppVersion; private String mDeploymentKey; private String mServerUrl = "https://codepush.azurewebsites.net/"; @@ -65,7 +66,7 @@ public class CodePush implements ReactPackage { try { PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0); - mAppVersion = pInfo.versionName; + mPListAppVersion = pInfo.versionName; } catch (PackageManager.NameNotFoundException e) { throw new CodePushUnknownException("Unable to get package info for " + mContext.getPackageName(), e); } @@ -96,7 +97,7 @@ public class CodePush implements ReactPackage { } public String getAppVersion() { - return mAppVersion; + return sAppVersionOverride == null ? mPListAppVersion : sAppVersionOverride; } public String getAssetsBundleFileName() { @@ -177,14 +178,14 @@ public class CodePush implements ReactPackage { String packageAppVersion = CodePushUtils.tryGetString(packageMetadata, "appVersion"); if (binaryModifiedDateDuringPackageInstall != null && binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime && - (isUsingTestConfiguration() || this.mAppVersion.equals(packageAppVersion))) { + (isUsingTestConfiguration() || this.getAppVersion().equals(packageAppVersion))) { CodePushUtils.logBundleUrl(packageFilePath); sIsRunningBinaryVersion = false; return packageFilePath; } else { // The binary version is newer. this.mDidUpdate = false; - if (!this.mIsDebugMode || !this.mAppVersion.equals(packageAppVersion)) { + if (!this.mIsDebugMode || !this.getAppVersion().equals(packageAppVersion)) { this.clearUpdates(); } @@ -249,6 +250,10 @@ public class CodePush implements ReactPackage { return sNeedToReportRollback; } + public static void overrideAppVersion(String appVersionOverride) { + sAppVersionOverride = appVersionOverride; + } + private void rollbackPackage() { WritableMap failedPackage = mUpdateManager.getCurrentPackage(); mSettingsManager.saveFailedUpdate(failedPackage); @@ -280,7 +285,7 @@ public class CodePush implements ReactPackage { CodePushNativeModule codePushModule = new CodePushNativeModule(reactApplicationContext, this, mUpdateManager, mTelemetryManager, mSettingsManager); CodePushDialog dialogModule = new CodePushDialog(reactApplicationContext); - List nativeModules = new ArrayList<>(); + List nativeModules = new ArrayList<>(); nativeModules.add(codePushModule); nativeModules.add(dialogModule); return nativeModules; diff --git a/ios/CodePush/CodePush.h b/ios/CodePush/CodePush.h index 04a617c..3e42060 100644 --- a/ios/CodePush/CodePush.h +++ b/ios/CodePush/CodePush.h @@ -30,7 +30,14 @@ + (NSString *)bundleAssetsPath; /* - * This methods allows dynamically setting the app's + * This method allows the version of the app's binary interface + * to be specified, which would otherwise default to the + * App Store version of the app. + */ ++ (void)overrideAppVersion:(NSString *)deploymentKey; + +/* + * This method allows dynamically setting the app's * deployment key, in addition to setting it via * the Info.plist file's CodePushDeploymentKey setting. */ @@ -45,7 +52,7 @@ @interface CodePushConfig : NSObject -@property (readonly) NSString *appVersion; +@property (copy) NSString *appVersion; @property (readonly) NSString *buildVersion; @property (readonly) NSDictionary *configuration; @property (copy) NSString *deploymentKey; diff --git a/ios/CodePush/CodePush.m b/ios/CodePush/CodePush.m index c8be248..e6616ab 100644 --- a/ios/CodePush/CodePush.m +++ b/ios/CodePush/CodePush.m @@ -73,7 +73,7 @@ static NSString *bundleResourceSubdirectory = nil; if (bundleResourceSubdirectory) { resourcePath = [resourcePath stringByAppendingPathComponent:bundleResourceSubdirectory]; } - + return [resourcePath stringByAppendingPathComponent:[CodePushUpdateUtils assetsFolderName]]; } @@ -159,6 +159,11 @@ static NSString *bundleResourceSubdirectory = nil; return applicationSupportDirectory; } ++ (void)overrideAppVersion:(NSString *)appVersion +{ + [CodePushConfig current].appVersion = appVersion; +} + + (void)setDeploymentKey:(NSString *)deploymentKey { [CodePushConfig current].deploymentKey = deploymentKey; diff --git a/ios/CodePush/CodePushConfig.m b/ios/CodePush/CodePushConfig.m index b84b757..7d12964 100644 --- a/ios/CodePush/CodePushConfig.m +++ b/ios/CodePush/CodePushConfig.m @@ -86,6 +86,11 @@ static NSString * const ServerURLConfigKey = @"serverUrl"; return [_configDictionary objectForKey:ClientUniqueIDConfigKey]; } +- (void)setAppVersion:(NSString *)appVersion +{ + [_configDictionary setValue:appVersion forKey:AppVersionConfigKey]; +} + - (void)setDeploymentKey:(NSString *)deploymentKey { [_configDictionary setValue:deploymentKey forKey:DeploymentKeyConfigKey];