@@ -25,7 +25,6 @@ @implementation CodePush {
25
25
26
26
// These keys represent the names we use to store data in NSUserDefaults
27
27
static NSString *const FailedUpdatesKey = @" CODE_PUSH_FAILED_UPDATES" ;
28
- static NSString *const LastDeploymentReportKey = @" CODE_PUSH_LAST_DEPLOYMENT_REPORT" ;
29
28
static NSString *const PendingUpdateKey = @" CODE_PUSH_PENDING_UPDATE" ;
30
29
31
30
// These keys are already "namespaced" by the PendingUpdateKey, so
@@ -35,8 +34,6 @@ @implementation CodePush {
35
34
36
35
// These keys are used to inspect/augment the metadata
37
36
// that is associated with an update's package.
38
- static NSString *const DeploymentKeyKey = @" deploymentKey" ;
39
- static NSString *const LabelKey = @" label" ;
40
37
static NSString *const PackageHashKey = @" packageHash" ;
41
38
static NSString *const PackageIsPendingKey = @" isPending" ;
42
39
@@ -168,19 +165,6 @@ - (void)dealloc
168
165
[[NSNotificationCenter defaultCenter ] removeObserver: self ];
169
166
}
170
167
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
-
184
168
- (instancetype )init
185
169
{
186
170
self = [super init ];
@@ -219,13 +203,6 @@ - (void)initializeUpdateAfterRestart
219
203
}
220
204
}
221
205
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
-
229
206
/*
230
207
* This method checks to see whether a specific package hash
231
208
* has previously failed installation.
@@ -296,13 +273,6 @@ - (void)loadBundle
296
273
});
297
274
}
298
275
299
- - (void )recordDeploymentStatusReported : (NSString *)appVersionOrPackageIdentifier
300
- {
301
- NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
302
- [preferences setValue: appVersionOrPackageIdentifier forKey: LastDeploymentReportKey];
303
- [preferences synchronize ];
304
- }
305
-
306
276
/*
307
277
* This method is used when an update has failed installation
308
278
* and the app needs to be rolled back to the previous bundle.
@@ -530,7 +500,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
530
500
rejecter:(RCTPromiseRejectBlock)reject)
531
501
{
532
502
[CodePush removePendingUpdate ];
533
- resolve ([ NSNull null ] );
503
+ resolve (nil );
534
504
}
535
505
536
506
/*
@@ -540,45 +510,35 @@ - (void)savePendingUpdate:(NSString *)packageHash
540
510
RCT_EXPORT_METHOD (getNewStatusReport:(RCTPromiseResolveBlock)resolve
541
511
rejecter:(RCTPromiseRejectBlock)reject)
542
512
{
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]);
555
523
return ;
556
524
}
557
525
}
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]);
568
531
return ;
569
532
}
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]);
577
537
return ;
578
538
}
579
- }
580
-
581
- resolve ([ NSNull null ] );
539
+
540
+ resolve ( nil );
541
+ } );
582
542
}
583
543
584
544
/*
0 commit comments