Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/ios/CodePush.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions src/ios/Utilities.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@interface Utilities : NSObject

+ (NSString*)getApplicationVersion;
+ (NSString*)getApplicationTimestamp;
+ (NSDate*)getApplicationBuildTime;

Expand Down
14 changes: 10 additions & 4 deletions src/ios/Utilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

@implementation Utilities

+ (NSString*)getApplicationVersion{
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
}

+ (NSString*)getApplicationTimestamp{
NSDate* applicationBuildTime = [self getApplicationBuildTime];
if (applicationBuildTime){
Expand All @@ -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