diff --git a/src/ios/CodePush.m b/src/ios/CodePush.m index 3df256fb..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 = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; + NSString* appVersion = [Utilities getApplicationVersion]; 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 getApplicationVersion]; + + 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 getApplicationVersion]; 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..9c0d203a 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,12 @@ + (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{ + //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