From df737ecae82d6f1c1f6993f95cac94697d771c78 Mon Sep 17 00:00:00 2001 From: max-mironov Date: Fri, 3 Feb 2017 05:58:49 -0800 Subject: [PATCH 1/4] Fixed issue for iOS when package folder was not cleared properly on updating app version This changes should fix https://github.com/Microsoft/cordova-plugin-code-push/issues/207. Tried to use more robust solution for determining correct build time for the app, Also add logic to also verify if the app version was changed before clearing deployments. Also moved repeated code for getting the app version to utility function. --- src/ios/CodePush.m | 13 +++++++++---- src/ios/Utilities.h | 1 + src/ios/Utilities.m | 20 ++++++++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/ios/CodePush.m b/src/ios/CodePush.m index 3df256fb..3049e74c 100644 --- a/src/ios/CodePush.m +++ b/src/ios/CodePush.m @@ -68,7 +68,7 @@ - (void)notifyApplicationReady:(CDVInvokedUrlCommand *)command { if ([CodePushPackageManager isBinaryFirstRun]) { // Report first run of a store version app [CodePushPackageManager markBinaryFirstRunFlag]; - NSString* appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; + NSString* appVersion = [Utilities getAppVersion]; NSString* deploymentKey = ((CDVViewController *)self.viewController).settings[DeploymentKeyPreference]; StatusReport* statusReport = [[StatusReport alloc] initWithStatus:STORE_VERSION andLabel:nil @@ -239,8 +239,13 @@ - (void)clearDeploymentsIfBinaryUpdated { NSString* deployedPackageNativeBuildTime = deployedPackageMetadata.nativeBuildTime; NSString* applicationBuildTime = [Utilities getApplicationTimestamp]; - if (deployedPackageNativeBuildTime != nil && applicationBuildTime != nil) { - if (![deployedPackageNativeBuildTime isEqualToString: applicationBuildTime]) { + NSString* deployedPackageVersion = deployedPackageMetadata.appVersion; + NSString* applicationVersion = [Utilities getAppVersion]; + + if (deployedPackageNativeBuildTime != nil && applicationBuildTime != nil && + deployedPackageVersion != nil && applicationVersion != nil) { + if (![deployedPackageNativeBuildTime isEqualToString: applicationBuildTime] || + ![deployedPackageVersion isEqualToString: applicationVersion]) { // package version is incompatible with installed native version [CodePushPackageManager cleanDeployments]; [CodePushPackageManager clearFailedUpdates]; @@ -407,7 +412,7 @@ - (void)isPendingUpdate:(CDVInvokedUrlCommand *)command { } - (void)getAppVersion:(CDVInvokedUrlCommand *)command { - NSString* version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; + NSString* version = [Utilities getAppVersion]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:version]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } diff --git a/src/ios/Utilities.h b/src/ios/Utilities.h index 9ccc71fa..c776d390 100644 --- a/src/ios/Utilities.h +++ b/src/ios/Utilities.h @@ -1,5 +1,6 @@ @interface Utilities : NSObject ++ (NSString*)getApplicationVersion; + (NSString*)getApplicationTimestamp; + (NSDate*)getApplicationBuildTime; diff --git a/src/ios/Utilities.m b/src/ios/Utilities.m index 77a5295e..ded3f259 100644 --- a/src/ios/Utilities.m +++ b/src/ios/Utilities.m @@ -2,6 +2,10 @@ @implementation Utilities ++ (NSString*)getApplicationVersion{ + return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; +} + + (NSString*)getApplicationTimestamp{ NSDate* applicationBuildTime = [self getApplicationBuildTime]; if (applicationBuildTime){ @@ -12,10 +16,18 @@ + (NSString*)getApplicationTimestamp{ return nil; } -+ (NSDate*)getApplicationBuildTime{ - NSString *appPath = [[NSBundle mainBundle] bundlePath]; - NSDictionary *executableAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:appPath error:nil]; - return [executableAttributes objectForKey:@"NSFileModificationDate"]; ++ (NSDate*)getApplicationBuildTime{ + NSString *dateStr = [NSString stringWithUTF8String:__DATE__]; + NSString *timeStr = [NSString stringWithUTF8String:__TIME__]; + + NSString *dateTimeStr = [NSString stringWithFormat:@"%@ %@", dateStr, timeStr]; + + // Convert to date + NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; + [dateFormat setDateFormat:@"LLL d yyyy HH:mm:ss"]; + NSDate *date = [dateFormat dateFromString:dateTimeStr]; + + return date; } @end \ No newline at end of file From 30c1b44cb8d63ef23739dd5f7c1bee2f79511b94 Mon Sep 17 00:00:00 2001 From: max-mironov Date: Sun, 5 Feb 2017 23:30:32 -0800 Subject: [PATCH 2/4] Fixed mistype for Utility GetApplicationVersion method --- src/ios/CodePush.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ios/CodePush.m b/src/ios/CodePush.m index 3049e74c..a63b617e 100644 --- a/src/ios/CodePush.m +++ b/src/ios/CodePush.m @@ -68,7 +68,7 @@ - (void)notifyApplicationReady:(CDVInvokedUrlCommand *)command { if ([CodePushPackageManager isBinaryFirstRun]) { // Report first run of a store version app [CodePushPackageManager markBinaryFirstRunFlag]; - NSString* appVersion = [Utilities getAppVersion]; + NSString* appVersion = [Utilities getApplicationVersion]; NSString* deploymentKey = ((CDVViewController *)self.viewController).settings[DeploymentKeyPreference]; StatusReport* statusReport = [[StatusReport alloc] initWithStatus:STORE_VERSION andLabel:nil @@ -240,7 +240,7 @@ - (void)clearDeploymentsIfBinaryUpdated { NSString* applicationBuildTime = [Utilities getApplicationTimestamp]; NSString* deployedPackageVersion = deployedPackageMetadata.appVersion; - NSString* applicationVersion = [Utilities getAppVersion]; + NSString* applicationVersion = [Utilities getApplicationVersion]; if (deployedPackageNativeBuildTime != nil && applicationBuildTime != nil && deployedPackageVersion != nil && applicationVersion != nil) { @@ -412,7 +412,7 @@ - (void)isPendingUpdate:(CDVInvokedUrlCommand *)command { } - (void)getAppVersion:(CDVInvokedUrlCommand *)command { - NSString* version = [Utilities getAppVersion]; + NSString* version = [Utilities getApplicationVersion]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:version]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } From c2650b18976cd828477f7ca2634a3ad0ade68317 Mon Sep 17 00:00:00 2001 From: max-mironov Date: Thu, 23 Feb 2017 04:30:39 -0800 Subject: [PATCH 3/4] Changed logic to get app modification date get from plist file because it should be updated on each rebuild --- src/ios/Utilities.m | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/ios/Utilities.m b/src/ios/Utilities.m index ded3f259..f10eab2b 100644 --- a/src/ios/Utilities.m +++ b/src/ios/Utilities.m @@ -16,18 +16,12 @@ + (NSString*)getApplicationTimestamp{ return nil; } -+ (NSDate*)getApplicationBuildTime{ - NSString *dateStr = [NSString stringWithUTF8String:__DATE__]; - NSString *timeStr = [NSString stringWithUTF8String:__TIME__]; - - NSString *dateTimeStr = [NSString stringWithFormat:@"%@ %@", dateStr, timeStr]; - - // Convert to date - NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; - [dateFormat setDateFormat:@"LLL d yyyy HH:mm:ss"]; - NSDate *date = [dateFormat dateFromString:dateTimeStr]; - - return date; ++ (NSDate*)getApplicationBuildTime{ + //get path for plist file to check modification date because iOS10.2 failed to get modification date of main bundle + NSString *appPlistPath = [[NSBundle mainBundle] pathForResource:nil ofType:@"plist"]; + NSDictionary *executableAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:appPlistPath error:nil]; + NSDate *fileDate = [executableAttributes objectForKEy:@"NSFileModificationDate"]; + return fileDate; } @end \ No newline at end of file From 9c6d56dbaecad4bba2eced1f267a7a5c5e0dc294 Mon Sep 17 00:00:00 2001 From: max-mironov Date: Thu, 23 Feb 2017 04:43:20 -0800 Subject: [PATCH 4/4] fixed typo --- src/ios/Utilities.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/Utilities.m b/src/ios/Utilities.m index f10eab2b..9c0d203a 100644 --- a/src/ios/Utilities.m +++ b/src/ios/Utilities.m @@ -20,7 +20,7 @@ + (NSDate*)getApplicationBuildTime{ //get path for plist file to check modification date because iOS10.2 failed to get modification date of main bundle NSString *appPlistPath = [[NSBundle mainBundle] pathForResource:nil ofType:@"plist"]; NSDictionary *executableAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:appPlistPath error:nil]; - NSDate *fileDate = [executableAttributes objectForKEy:@"NSFileModificationDate"]; + NSDate *fileDate = [executableAttributes objectForKey:@"NSFileModificationDate"]; return fileDate; }