@@ -25,7 +25,6 @@ @implementation CodePush {
2525
2626// These keys represent the names we use to store data in NSUserDefaults
2727static NSString *const FailedUpdatesKey = @" CODE_PUSH_FAILED_UPDATES" ;
28- static NSString *const LastDeploymentReportKey = @" CODE_PUSH_LAST_DEPLOYMENT_REPORT" ;
2928static NSString *const PendingUpdateKey = @" CODE_PUSH_PENDING_UPDATE" ;
3029
3130// These keys are already "namespaced" by the PendingUpdateKey, so
@@ -35,8 +34,6 @@ @implementation CodePush {
3534
3635// These keys are used to inspect/augment the metadata
3736// that is associated with an update's package.
38- static NSString *const DeploymentKeyKey = @" deploymentKey" ;
39- static NSString *const LabelKey = @" label" ;
4037static NSString *const PackageHashKey = @" packageHash" ;
4138static NSString *const PackageIsPendingKey = @" isPending" ;
4239
@@ -168,19 +165,6 @@ - (void)dealloc
168165 [[NSNotificationCenter defaultCenter ] removeObserver: self ];
169166}
170167
171- - (NSString *)getPackageStatusReportIdentifier : (NSDictionary *)package
172- {
173- // Because deploymentKeys can be dynamically switched, we use a
174- // combination of the deploymentKey and label as the packageIdentifier.
175- NSString *deploymentKey = [package objectForKey: DeploymentKeyKey];
176- NSString *label = [package objectForKey: LabelKey];
177- if (deploymentKey && label) {
178- return [[deploymentKey stringByAppendingString: @" :" ] stringByAppendingString: label];
179- } else {
180- return nil ;
181- }
182- }
183-
184168- (instancetype )init
185169{
186170 self = [super init ];
@@ -219,13 +203,6 @@ - (void)initializeUpdateAfterRestart
219203 }
220204}
221205
222- - (BOOL )isDeploymentStatusNotYetReported : (NSString *)appVersionOrPackageIdentifier
223- {
224- NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
225- NSString *sentStatusReportIdentifier = [preferences objectForKey: LastDeploymentReportKey];
226- return sentStatusReportIdentifier == nil || ![sentStatusReportIdentifier isEqualToString: appVersionOrPackageIdentifier];
227- }
228-
229206/*
230207 * This method checks to see whether a specific package hash
231208 * has previously failed installation.
@@ -296,13 +273,6 @@ - (void)loadBundle
296273 });
297274}
298275
299- - (void )recordDeploymentStatusReported : (NSString *)appVersionOrPackageIdentifier
300- {
301- NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
302- [preferences setValue: appVersionOrPackageIdentifier forKey: LastDeploymentReportKey];
303- [preferences synchronize ];
304- }
305-
306276/*
307277 * This method is used when an update has failed installation
308278 * and the app needs to be rolled back to the previous bundle.
@@ -530,7 +500,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
530500 rejecter:(RCTPromiseRejectBlock)reject)
531501{
532502 [CodePush removePendingUpdate ];
533- resolve ([ NSNull null ] );
503+ resolve (nil );
534504}
535505
536506/*
@@ -540,45 +510,35 @@ - (void)savePendingUpdate:(NSString *)packageHash
540510RCT_EXPORT_METHOD (getNewStatusReport:(RCTPromiseResolveBlock)resolve
541511 rejecter:(RCTPromiseRejectBlock)reject)
542512{
543- if (needToReportRollback) {
544- // Check if there was a rollback that was not yet reported
545- needToReportRollback = NO ;
546- NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
547- NSMutableArray *failedUpdates = [preferences objectForKey: FailedUpdatesKey];
548- if (failedUpdates) {
549- NSDictionary *lastFailedPackage = [failedUpdates lastObject ];
550- if (lastFailedPackage) {
551- NSString *lastFailedPackageIdentifier = [self getPackageStatusReportIdentifier: lastFailedPackage];
552- if (lastFailedPackageIdentifier && [self isDeploymentStatusNotYetReported: lastFailedPackageIdentifier]) {
553- [self recordDeploymentStatusReported: lastFailedPackageIdentifier];
554- resolve (@{ @" package" : lastFailedPackage, @" status" : DeploymentFailed });
513+
514+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
515+ if (needToReportRollback) {
516+ needToReportRollback = NO ;
517+ NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
518+ NSMutableArray *failedUpdates = [preferences objectForKey: FailedUpdatesKey];
519+ if (failedUpdates) {
520+ NSDictionary *lastFailedPackage = [failedUpdates lastObject ];
521+ if (lastFailedPackage) {
522+ resolve ([CodePushTelemetryManager getRollbackReport: lastFailedPackage]);
555523 return ;
556524 }
557525 }
558- }
559- } else if (_isFirstRunAfterUpdate) {
560- // Check if the current CodePush package has been reported
561- NSError *error;
562- NSDictionary *currentPackage = [CodePushPackage getCurrentPackage: &error];
563- if (!error && currentPackage) {
564- NSString *currentPackageIdentifier = [self getPackageStatusReportIdentifier: currentPackage];
565- if (currentPackageIdentifier && [self isDeploymentStatusNotYetReported: currentPackageIdentifier]) {
566- [self recordDeploymentStatusReported: currentPackageIdentifier];
567- resolve (@{ @" package" : currentPackage, @" status" : DeploymentSucceeded });
526+ } else if (_isFirstRunAfterUpdate) {
527+ NSError *error;
528+ NSDictionary *currentPackage = [CodePushPackage getCurrentPackage: &error];
529+ if (!error && currentPackage) {
530+ resolve ([CodePushTelemetryManager getUpdateReport: currentPackage]);
568531 return ;
569532 }
570- }
571- } else if (isRunningBinaryVersion || [_bridge.bundleURL.scheme hasPrefix: @" http" ]) {
572- // Check if the current appVersion has been reported.
573- NSString *appVersion = [[CodePushConfig current ] appVersion ];
574- if ([self isDeploymentStatusNotYetReported: appVersion]) {
575- [self recordDeploymentStatusReported: appVersion];
576- resolve (@{ @" appVersion" : appVersion });
533+ } else if (isRunningBinaryVersion || [_bridge.bundleURL.scheme hasPrefix: @" http" ]) {
534+ // Check if the current appVersion has been reported.
535+ NSString *appVersion = [[CodePushConfig current ] appVersion ];
536+ resolve ([CodePushTelemetryManager getBinaryUpdateReport: appVersion]);
577537 return ;
578538 }
579- }
580-
581- resolve ([ NSNull null ] );
539+
540+ resolve ( nil );
541+ } );
582542}
583543
584544/*
0 commit comments