@@ -23,7 +23,6 @@ @implementation CodePush {
23
23
24
24
// These keys represent the names we use to store data in NSUserDefaults
25
25
static NSString *const FailedUpdatesKey = @" CODE_PUSH_FAILED_UPDATES" ;
26
- static NSString *const LastDeploymentReportKey = @" CODE_PUSH_LAST_DEPLOYMENT_REPORT" ;
27
26
static NSString *const PendingUpdateKey = @" CODE_PUSH_PENDING_UPDATE" ;
28
27
29
28
// These keys are already "namespaced" by the PendingUpdateKey, so
@@ -33,8 +32,6 @@ @implementation CodePush {
33
32
34
33
// These keys are used to inspect/augment the metadata
35
34
// that is associated with an update's package.
36
- static NSString *const DeploymentKeyKey = @" deploymentKey" ;
37
- static NSString *const LabelKey = @" label" ;
38
35
static NSString *const PackageHashKey = @" packageHash" ;
39
36
static NSString *const PackageIsPendingKey = @" isPending" ;
40
37
@@ -161,36 +158,6 @@ - (void)dealloc
161
158
[[NSNotificationCenter defaultCenter ] removeObserver: self ];
162
159
}
163
160
164
- - (NSString *)getDeploymentKeyFromStatusReportIdentifier : (NSString *)statusReportIdentifier
165
- {
166
- return [[statusReportIdentifier componentsSeparatedByString: @" :" ] firstObject ];
167
- }
168
-
169
- - (NSString *)getPackageStatusReportIdentifier : (NSDictionary *)package
170
- {
171
- // Because deploymentKeys can be dynamically switched, we use a
172
- // combination of the deploymentKey and label as the packageIdentifier.
173
- NSString *deploymentKey = [package objectForKey: DeploymentKeyKey];
174
- NSString *label = [package objectForKey: LabelKey];
175
- if (deploymentKey && label) {
176
- return [[deploymentKey stringByAppendingString: @" :" ] stringByAppendingString: label];
177
- } else {
178
- return nil ;
179
- }
180
- }
181
-
182
- - (NSString *)getPreviousStatusReportIdentifier
183
- {
184
- NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
185
- NSString *sentStatusReportIdentifier = [preferences objectForKey: LastDeploymentReportKey];
186
- return sentStatusReportIdentifier;
187
- }
188
-
189
- - (NSString *)getVersionLabelFromStatusReportIdentifier : (NSString *)statusReportIdentifier
190
- {
191
- return [[statusReportIdentifier componentsSeparatedByString: @" :" ] lastObject ];
192
- }
193
-
194
161
- (instancetype )init
195
162
{
196
163
self = [super init ];
@@ -277,11 +244,6 @@ - (BOOL)isPendingUpdate:(NSString*)packageHash
277
244
return updateIsPending;
278
245
}
279
246
280
- - (BOOL )isStatusReportIdentifierCodePushLabel : (NSString *)statusReportIdentifier
281
- {
282
- return statusReportIdentifier != nil && [statusReportIdentifier containsString: @" :" ];
283
- }
284
-
285
247
/*
286
248
* This method updates the React Native bridge's bundle URL
287
249
* to point at the latest CodePush update, and then restarts
@@ -304,13 +266,6 @@ - (void)loadBundle
304
266
});
305
267
}
306
268
307
- - (void )recordDeploymentStatusReported : (NSString *)appVersionOrPackageIdentifier
308
- {
309
- NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
310
- [preferences setValue: appVersionOrPackageIdentifier forKey: LastDeploymentReportKey];
311
- [preferences synchronize ];
312
- }
313
-
314
269
/*
315
270
* This method is used when an update has failed installation
316
271
* and the app needs to be rolled back to the previous bundle.
@@ -556,38 +511,33 @@ - (void)savePendingUpdate:(NSString *)packageHash
556
511
if (failedUpdates) {
557
512
NSDictionary *lastFailedPackage = [failedUpdates lastObject ];
558
513
if (lastFailedPackage) {
559
- NSString *lastFailedPackageIdentifier = [self getPackageStatusReportIdentifier: lastFailedPackage];
560
- NSString *previousStatusReportIdentifier = [self getPreviousStatusReportIdentifier ];
561
- if (lastFailedPackageIdentifier && (previousStatusReportIdentifier == nil || ![previousStatusReportIdentifier isEqualToString: lastFailedPackageIdentifier])) {
562
- [self recordDeploymentStatusReported: lastFailedPackageIdentifier];
563
- resolve (@{
564
- @" package" : lastFailedPackage,
565
- @" status" : DeploymentFailed
566
- });
567
- return ;
568
- }
514
+ resolve (@{
515
+ @" package" : lastFailedPackage,
516
+ @" status" : DeploymentFailed
517
+ });
518
+ return ;
569
519
}
570
520
}
571
521
} else if (_isFirstRunAfterUpdate) {
572
522
// Check if the current CodePush package has been reported
573
523
NSError *error;
574
524
NSDictionary *currentPackage = [CodePushPackage getCurrentPackage: &error];
575
525
if (!error && currentPackage) {
576
- NSString *currentPackageIdentifier = [self getPackageStatusReportIdentifier: currentPackage];
577
- NSString *previousStatusReportIdentifier = [self getPreviousStatusReportIdentifier ];
526
+ NSString *currentPackageIdentifier = [CodePushStatusReport getPackageStatusReportIdentifier: currentPackage];
527
+ NSString *previousStatusReportIdentifier = [CodePushStatusReport getPreviousStatusReportIdentifier ];
578
528
if (currentPackageIdentifier) {
579
529
if (previousStatusReportIdentifier == nil ) {
580
- [self recordDeploymentStatusReported: currentPackageIdentifier];
530
+ [CodePushStatusReport recordDeploymentStatusReported: currentPackageIdentifier];
581
531
resolve (@{
582
532
@" package" : currentPackage,
583
533
@" status" : DeploymentSucceeded
584
534
});
585
535
return ;
586
536
} else if (![previousStatusReportIdentifier isEqualToString: currentPackageIdentifier]) {
587
- [self recordDeploymentStatusReported: currentPackageIdentifier];
588
- if ([self isStatusReportIdentifierCodePushLabel: previousStatusReportIdentifier]) {
589
- NSString *previousDeploymentKey = [self getDeploymentKeyFromStatusReportIdentifier: previousStatusReportIdentifier];
590
- NSString *previousLabel = [self getVersionLabelFromStatusReportIdentifier: previousStatusReportIdentifier];
537
+ [CodePushStatusReport recordDeploymentStatusReported: currentPackageIdentifier];
538
+ if ([CodePushStatusReport isStatusReportIdentifierCodePushLabel: previousStatusReportIdentifier]) {
539
+ NSString *previousDeploymentKey = [CodePushStatusReport getDeploymentKeyFromStatusReportIdentifier: previousStatusReportIdentifier];
540
+ NSString *previousLabel = [CodePushStatusReport getVersionLabelFromStatusReportIdentifier: previousStatusReportIdentifier];
591
541
resolve (@{
592
542
@" package" : currentPackage,
593
543
@" status" : DeploymentSucceeded,
@@ -609,16 +559,16 @@ - (void)savePendingUpdate:(NSString *)packageHash
609
559
} else if (isRunningBinaryVersion || [_bridge.bundleURL.scheme hasPrefix: @" http" ]) {
610
560
// Check if the current appVersion has been reported.
611
561
NSString *appVersion = [[CodePushConfig current ] appVersion ];
612
- NSString *previousStatusReportIdentifier = [self getPreviousStatusReportIdentifier ];
562
+ NSString *previousStatusReportIdentifier = [CodePushStatusReport getPreviousStatusReportIdentifier ];
613
563
if (previousStatusReportIdentifier == nil ) {
614
- [self recordDeploymentStatusReported: appVersion];
564
+ [CodePushStatusReport recordDeploymentStatusReported: appVersion];
615
565
resolve (@{ @" appVersion" : appVersion });
616
566
return ;
617
567
} else if (![previousStatusReportIdentifier isEqualToString: appVersion]) {
618
- [self recordDeploymentStatusReported: appVersion];
619
- if ([self isStatusReportIdentifierCodePushLabel: previousStatusReportIdentifier]) {
620
- NSString *previousDeploymentKey = [self getDeploymentKeyFromStatusReportIdentifier: previousStatusReportIdentifier];
621
- NSString *previousLabel = [self getVersionLabelFromStatusReportIdentifier: previousStatusReportIdentifier];
568
+ [CodePushStatusReport recordDeploymentStatusReported: appVersion];
569
+ if ([CodePushStatusReport isStatusReportIdentifierCodePushLabel: previousStatusReportIdentifier]) {
570
+ NSString *previousDeploymentKey = [CodePushStatusReport getDeploymentKeyFromStatusReportIdentifier: previousStatusReportIdentifier];
571
+ NSString *previousLabel = [CodePushStatusReport getVersionLabelFromStatusReportIdentifier: previousStatusReportIdentifier];
622
572
resolve (@{
623
573
@" appVersion" : appVersion,
624
574
@" previousDeploymentKey" : previousDeploymentKey,
0 commit comments