mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-19 18:13:46 +08:00
Allow the binary version to be specified independently of the app version
This commit is contained in:
@@ -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<NativeModule> nativeModules = new ArrayList<>();
|
||||
List<NativeModule> nativeModules = new ArrayList<>();
|
||||
nativeModules.add(codePushModule);
|
||||
nativeModules.add(dialogModule);
|
||||
return nativeModules;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user