@@ -23,7 +23,6 @@ @implementation CodePush {
2323
2424// These keys represent the names we use to store data in NSUserDefaults
2525static NSString *const FailedUpdatesKey = @" CODE_PUSH_FAILED_UPDATES" ;
26- static NSString *const LastDeploymentReportKey = @" CODE_PUSH_LAST_DEPLOYMENT_REPORT" ;
2726static NSString *const PendingUpdateKey = @" CODE_PUSH_PENDING_UPDATE" ;
2827
2928// These keys are already "namespaced" by the PendingUpdateKey, so
@@ -33,8 +32,6 @@ @implementation CodePush {
3332
3433// These keys are used to inspect/augment the metadata
3534// that is associated with an update's package.
36- static NSString *const DeploymentKeyKey = @" deploymentKey" ;
37- static NSString *const LabelKey = @" label" ;
3835static NSString *const PackageHashKey = @" packageHash" ;
3936static NSString *const PackageIsPendingKey = @" isPending" ;
4037
@@ -161,36 +158,6 @@ - (void)dealloc
161158 [[NSNotificationCenter defaultCenter ] removeObserver: self ];
162159}
163160
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-
194161- (instancetype )init
195162{
196163 self = [super init ];
@@ -277,11 +244,6 @@ - (BOOL)isPendingUpdate:(NSString*)packageHash
277244 return updateIsPending;
278245}
279246
280- - (BOOL )isStatusReportIdentifierCodePushLabel : (NSString *)statusReportIdentifier
281- {
282- return statusReportIdentifier != nil && [statusReportIdentifier containsString: @" :" ];
283- }
284-
285247/*
286248 * This method updates the React Native bridge's bundle URL
287249 * to point at the latest CodePush update, and then restarts
@@ -304,13 +266,6 @@ - (void)loadBundle
304266 });
305267}
306268
307- - (void )recordDeploymentStatusReported : (NSString *)appVersionOrPackageIdentifier
308- {
309- NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
310- [preferences setValue: appVersionOrPackageIdentifier forKey: LastDeploymentReportKey];
311- [preferences synchronize ];
312- }
313-
314269/*
315270 * This method is used when an update has failed installation
316271 * and the app needs to be rolled back to the previous bundle.
@@ -556,38 +511,33 @@ - (void)savePendingUpdate:(NSString *)packageHash
556511 if (failedUpdates) {
557512 NSDictionary *lastFailedPackage = [failedUpdates lastObject ];
558513 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 ;
569519 }
570520 }
571521 } else if (_isFirstRunAfterUpdate) {
572522 // Check if the current CodePush package has been reported
573523 NSError *error;
574524 NSDictionary *currentPackage = [CodePushPackage getCurrentPackage: &error];
575525 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 ];
578528 if (currentPackageIdentifier) {
579529 if (previousStatusReportIdentifier == nil ) {
580- [self recordDeploymentStatusReported: currentPackageIdentifier];
530+ [CodePushStatusReport recordDeploymentStatusReported: currentPackageIdentifier];
581531 resolve (@{
582532 @" package" : currentPackage,
583533 @" status" : DeploymentSucceeded
584534 });
585535 return ;
586536 } 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];
591541 resolve (@{
592542 @" package" : currentPackage,
593543 @" status" : DeploymentSucceeded,
@@ -609,16 +559,16 @@ - (void)savePendingUpdate:(NSString *)packageHash
609559 } else if (isRunningBinaryVersion || [_bridge.bundleURL.scheme hasPrefix: @" http" ]) {
610560 // Check if the current appVersion has been reported.
611561 NSString *appVersion = [[CodePushConfig current ] appVersion ];
612- NSString *previousStatusReportIdentifier = [self getPreviousStatusReportIdentifier ];
562+ NSString *previousStatusReportIdentifier = [CodePushStatusReport getPreviousStatusReportIdentifier ];
613563 if (previousStatusReportIdentifier == nil ) {
614- [self recordDeploymentStatusReported: appVersion];
564+ [CodePushStatusReport recordDeploymentStatusReported: appVersion];
615565 resolve (@{ @" appVersion" : appVersion });
616566 return ;
617567 } 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];
622572 resolve (@{
623573 @" appVersion" : appVersion,
624574 @" previousDeploymentKey" : previousDeploymentKey,
0 commit comments