From 2d5d80f6065771a754195c4d63d801a0372899d2 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 21 Jan 2016 01:33:01 -0800 Subject: [PATCH] fix issue with packager --- CodePush.m | 31 +++++++------------ CodePushConfig.m | 4 +-- .../microsoft/codepush/react/CodePush.java | 20 ++++++------ request-fetch-adapter.js | 14 ++++----- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/CodePush.m b/CodePush.m index e9b4474..cab26cf 100644 --- a/CodePush.m +++ b/CodePush.m @@ -18,13 +18,13 @@ static BOOL isRunningBinaryVersion = NO; static BOOL testConfigurationFlag = NO; // These constants represent valid deployment statuses -static NSString *const DeploymentSucceeded = @"DeploymentSucceeded"; static NSString *const DeploymentFailed = @"DeploymentFailed"; +static NSString *const DeploymentSucceeded = @"DeploymentSucceeded"; // These keys represent the names we use to store data in NSUserDefaults static NSString *const FailedUpdatesKey = @"CODE_PUSH_FAILED_UPDATES"; -static NSString *const PendingUpdateKey = @"CODE_PUSH_PENDING_UPDATE"; static NSString *const LastDeploymentReportKey = @"CODE_PUSH_LAST_DEPLOYMENT_REPORT"; +static NSString *const PendingUpdateKey = @"CODE_PUSH_PENDING_UPDATE"; // These keys are already "namespaced" by the PendingUpdateKey, so // their values don't need to be obfuscated to prevent collision with app data @@ -552,29 +552,22 @@ RCT_EXPORT_METHOD(getNewStatusReport:(RCTPromiseResolveBlock)resolve } else if (_isFirstRunAfterUpdate) { // Check if the current CodePush package has been reported NSError *error; - NSDictionary* currentPackage = [CodePushPackage getCurrentPackage:&error]; - if (currentPackage) { - NSString* currentPackageIdentifier = [self getPackageStatusReportIdentifier:currentPackage]; + NSDictionary *currentPackage = [CodePushPackage getCurrentPackage:&error]; + if (!error && currentPackage) { + NSString *currentPackageIdentifier = [self getPackageStatusReportIdentifier:currentPackage]; if (currentPackageIdentifier && [self isDeploymentStatusNotYetReported:currentPackageIdentifier]) { [self recordDeploymentStatusReported:currentPackageIdentifier]; resolve(@{ @"package": currentPackage, @"status": DeploymentSucceeded }); return; } } - } else { - if (isRunningBinaryVersion) { - // Check if the current appVersion has been reported. Use date as the binary identifier to - // handle binary releases that do not modify the appVersion. - NSURL *binaryJsBundleUrl = [CodePush bundleURL]; - NSDictionary *binaryFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[binaryJsBundleUrl path] error:nil]; - NSTimeInterval binaryDate = [[binaryFileAttributes objectForKey:NSFileModificationDate] timeIntervalSince1970]; - NSString* binaryIdentifier = [NSString stringWithFormat:@"%f", binaryDate]; - - if ([self isDeploymentStatusNotYetReported:binaryIdentifier]) { - [self recordDeploymentStatusReported:binaryIdentifier]; - resolve(@{ @"appVersion": [[CodePushConfig current] appVersion] }); - return; - } + } else if (isRunningBinaryVersion || [_bridge.bundleURL.scheme hasPrefix:@"http"]) { + // Check if the current appVersion has been reported. + NSString *appVersion = [[CodePushConfig current] appVersion]; + if ([self isDeploymentStatusNotYetReported:appVersion]) { + [self recordDeploymentStatusReported:appVersion]; + resolve(@{ @"appVersion": appVersion }); + return; } } diff --git a/CodePushConfig.m b/CodePushConfig.m index 8a7afa7..9ea11ff 100644 --- a/CodePushConfig.m +++ b/CodePushConfig.m @@ -33,8 +33,8 @@ static NSString * const ServerURLConfigKey = @"serverUrl"; NSString *deploymentKey = [infoDictionary objectForKey:@"CodePushDeploymentKey"]; NSString *serverURL = [infoDictionary objectForKey:@"CodePushServerURL"]; - NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; - NSString* clientUniqueId = [userDefaults stringForKey:ClientUniqueIDConfigKey]; + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + NSString *clientUniqueId = [userDefaults stringForKey:ClientUniqueIDConfigKey]; if (clientUniqueId == nil) { clientUniqueId = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; [userDefaults setObject:clientUniqueId forKey:ClientUniqueIDConfigKey]; 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 7919a45..4474074 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 @@ -491,17 +491,15 @@ public class CodePush { return; } } - } else { - if (isRunningBinaryVersion) { - // Check if the current appVersion has been reported. - String binaryIdentifier = "" + getBinaryResourcesModifiedTime(); - if (isDeploymentStatusNotYetReported(binaryIdentifier)) { - recordDeploymentStatusReported(binaryIdentifier); - WritableNativeMap reportMap = new WritableNativeMap(); - reportMap.putString("appVersion", appVersion); - promise.resolve(reportMap); - return; - } + } else if (isRunningBinaryVersion) { + // Check if the current appVersion has been reported. + String binaryIdentifier = "" + getBinaryResourcesModifiedTime(); + if (isDeploymentStatusNotYetReported(binaryIdentifier)) { + recordDeploymentStatusReported(binaryIdentifier); + WritableNativeMap reportMap = new WritableNativeMap(); + reportMap.putString("appVersion", appVersion); + promise.resolve(reportMap); + return; } } diff --git a/request-fetch-adapter.js b/request-fetch-adapter.js index 0646918..eeeac81 100644 --- a/request-fetch-adapter.js +++ b/request-fetch-adapter.js @@ -1,8 +1,8 @@ module.exports = { - async request(verb, url, body, callback) { - if (typeof body === "function") { - callback = body; - body = null; + async request(verb, url, requestBody, callback) { + if (typeof requestBody === "function") { + callback = requestBody; + requestBody = null; } var headers = { @@ -10,15 +10,15 @@ module.exports = { "Content-Type": "application/json" }; - if (body && typeof body === "object") { - body = JSON.stringify(body); + if (requestBody && typeof requestBody === "object") { + requestBody = JSON.stringify(requestBody); } try { const response = await fetch(url, { method: getHttpMethodName(verb), headers: headers, - body: body + body: requestBody }); const statusCode = response.status;