diff --git a/CodePush.h b/CodePush.h index 7704421..e3a016d 100644 --- a/CodePush.h +++ b/CodePush.h @@ -91,8 +91,8 @@ failCallback:(void (^)(NSError *err))failCallback; @interface CodePushTelemetryManager : NSObject + (NSDictionary *)getBinaryUpdateReport:(NSString *)appVersion; -+ (NSDictionary *)getUpdateReport:(NSDictionary *)currentPackage; + (NSDictionary *)getRollbackReport:(NSDictionary *)lastFailedPackage; ++ (NSDictionary *)getUpdateReport:(NSDictionary *)currentPackage; @end diff --git a/CodePush.m b/CodePush.m index 933621d..5e2370e 100644 --- a/CodePush.m +++ b/CodePush.m @@ -503,32 +503,35 @@ RCT_EXPORT_METHOD(notifyApplicationReady:(RCTPromiseResolveBlock)resolve RCT_EXPORT_METHOD(getNewStatusReport:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { - if (needToReportRollback) { - needToReportRollback = NO; - NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; - NSMutableArray *failedUpdates = [preferences objectForKey:FailedUpdatesKey]; - if (failedUpdates) { - NSDictionary *lastFailedPackage = [failedUpdates lastObject]; - if (lastFailedPackage) { - resolve([CodePushTelemetryManager getRollbackReport:lastFailedPackage]); + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + if (needToReportRollback) { + needToReportRollback = NO; + NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; + NSMutableArray *failedUpdates = [preferences objectForKey:FailedUpdatesKey]; + if (failedUpdates) { + NSDictionary *lastFailedPackage = [failedUpdates lastObject]; + if (lastFailedPackage) { + resolve([CodePushTelemetryManager getRollbackReport:lastFailedPackage]); + return; + } + } + } else if (_isFirstRunAfterUpdate) { + NSError *error; + NSDictionary *currentPackage = [CodePushPackage getCurrentPackage:&error]; + if (!error && currentPackage) { + resolve([CodePushTelemetryManager getUpdateReport:currentPackage]); return; } - } - } else if (_isFirstRunAfterUpdate) { - NSError *error; - NSDictionary *currentPackage = [CodePushPackage getCurrentPackage:&error]; - if (!error && currentPackage) { - resolve([CodePushTelemetryManager getUpdateReport:currentPackage]); + } else if (isRunningBinaryVersion || [_bridge.bundleURL.scheme hasPrefix:@"http"]) { + // Check if the current appVersion has been reported. + NSString *appVersion = [[CodePushConfig current] appVersion]; + resolve([CodePushTelemetryManager getBinaryUpdateReport:appVersion]); return; } - } else if (isRunningBinaryVersion || [_bridge.bundleURL.scheme hasPrefix:@"http"]) { - // Check if the current appVersion has been reported. - NSString *appVersion = [[CodePushConfig current] appVersion]; - resolve([CodePushTelemetryManager getBinaryUpdateReport:appVersion]); - return; - } - - resolve(nil); + + resolve(nil); + }); } /* diff --git a/CodePushTelemetryManager.m b/CodePushTelemetryManager.m index 6c5194e..1feff55 100644 --- a/CodePushTelemetryManager.m +++ b/CodePushTelemetryManager.m @@ -20,16 +20,16 @@ static NSString *const LastDeploymentReportKey = @"CODE_PUSH_LAST_DEPLOYMENT_REP NSString *previousDeploymentKey = [self getDeploymentKeyFromStatusReportIdentifier:previousStatusReportIdentifier]; NSString *previousLabel = [self getVersionLabelFromStatusReportIdentifier:previousStatusReportIdentifier]; return @{ - @"appVersion": appVersion, - @"previousDeploymentKey": previousDeploymentKey, - @"previousLabelOrAppVersion": previousLabel - }; + @"appVersion": appVersion, + @"previousDeploymentKey": previousDeploymentKey, + @"previousLabelOrAppVersion": previousLabel + }; } else { // Previous status report was with a binary app version. return @{ - @"appVersion": appVersion, - @"previousLabelOrAppVersion": previousStatusReportIdentifier - }; + @"appVersion": appVersion, + @"previousLabelOrAppVersion": previousStatusReportIdentifier + }; } } @@ -52,27 +52,27 @@ static NSString *const LastDeploymentReportKey = @"CODE_PUSH_LAST_DEPLOYMENT_REP if (previousStatusReportIdentifier == nil) { [self recordDeploymentStatusReported:currentPackageIdentifier]; return @{ - @"package": currentPackage, - @"status": DeploymentSucceeded - }; + @"package": currentPackage, + @"status": DeploymentSucceeded + }; } else if (![previousStatusReportIdentifier isEqualToString:currentPackageIdentifier]) { [self recordDeploymentStatusReported:currentPackageIdentifier]; if ([self isStatusReportIdentifierCodePushLabel:previousStatusReportIdentifier]) { NSString *previousDeploymentKey = [self getDeploymentKeyFromStatusReportIdentifier:previousStatusReportIdentifier]; NSString *previousLabel = [self getVersionLabelFromStatusReportIdentifier:previousStatusReportIdentifier]; return @{ - @"package": currentPackage, - @"status": DeploymentSucceeded, - @"previousDeploymentKey": previousDeploymentKey, - @"previousLabelOrAppVersion": previousLabel - }; + @"package": currentPackage, + @"status": DeploymentSucceeded, + @"previousDeploymentKey": previousDeploymentKey, + @"previousLabelOrAppVersion": previousLabel + }; } else { // Previous status report was with a binary app version. return @{ - @"package": currentPackage, - @"status": DeploymentSucceeded, - @"previousLabelOrAppVersion": previousStatusReportIdentifier - }; + @"package": currentPackage, + @"status": DeploymentSucceeded, + @"previousLabelOrAppVersion": previousStatusReportIdentifier + }; } } } @@ -80,6 +80,8 @@ static NSString *const LastDeploymentReportKey = @"CODE_PUSH_LAST_DEPLOYMENT_REP return nil; } +#pragma mark - private methods + + (NSString *)getDeploymentKeyFromStatusReportIdentifier:(NSString *)statusReportIdentifier { return [[statusReportIdentifier componentsSeparatedByString:@":"] firstObject]; 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 59758df..937806f 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 @@ -63,10 +63,10 @@ public class CodePush { private final String REACT_DEV_BUNDLE_CACHE_FILE_NAME = "ReactNativeDevBundle.js"; // Helper classes. + private CodePushNativeModule codePushNativeModule; private CodePushPackage codePushPackage; private CodePushReactPackage codePushReactPackage; private CodePushTelemetryManager codePushTelemetryManager; - private CodePushNativeModule codePushNativeModule; // Config properties. private String deploymentKey;