|
16 | 16 |
|
17 | 17 | static NSString *const keyPushyInfo = @"REACTNATIVECN_PUSHY_INFO_KEY";
|
18 | 18 | static NSString *const paramPackageVersion = @"packageVersion";
|
| 19 | +static NSString *const paramBuildTime = @"buildTime"; |
19 | 20 | static NSString *const paramLastVersion = @"lastVersion";
|
20 | 21 | static NSString *const paramCurrentVersion = @"currentVersion";
|
21 | 22 | static NSString *const paramIsFirstTime = @"isFirstTime";
|
@@ -70,20 +71,28 @@ + (NSURL *)bundleURL
|
70 | 71 | {
|
71 | 72 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
72 | 73 |
|
| 74 | + // Check for version changes first |
| 75 | + NSString *curPackageVersion = [RCTPushy packageVersion]; |
| 76 | + NSString *curBuildTime = [RCTPushy buildTime]; |
| 77 | + NSString *storedPackageVersion = [defaults stringForKey:paramPackageVersion]; |
| 78 | + NSString *storedBuildTime = [defaults stringForKey:paramBuildTime]; |
| 79 | + |
| 80 | + BOOL packageVersionChanged = ![curPackageVersion isEqualToString:storedPackageVersion]; |
| 81 | + BOOL buildTimeChanged = ![curBuildTime isEqualToString:storedBuildTime]; |
| 82 | + |
| 83 | + if (packageVersionChanged || buildTimeChanged) { |
| 84 | + // Clear all update data and store new versions |
| 85 | + [defaults setObject:nil forKey:keyPushyInfo]; |
| 86 | + [defaults setObject:nil forKey:keyHashInfo]; |
| 87 | + [defaults setObject:@(YES) forKey:KeyPackageUpdatedMarked]; |
| 88 | + [defaults setObject:curPackageVersion forKey:paramPackageVersion]; |
| 89 | + [defaults setObject:curBuildTime forKey:paramBuildTime]; |
| 90 | + |
| 91 | + // ...need clear files later |
| 92 | + } |
| 93 | + |
73 | 94 | NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
|
74 | 95 | if (pushyInfo) {
|
75 |
| - NSString *curPackageVersion = [RCTPushy packageVersion]; |
76 |
| - NSString *packageVersion = [pushyInfo objectForKey:paramPackageVersion]; |
77 |
| - |
78 |
| - BOOL needClearPushyInfo = ![curPackageVersion isEqualToString:packageVersion]; |
79 |
| - if (needClearPushyInfo) { |
80 |
| - [defaults setObject:nil forKey:keyPushyInfo]; |
81 |
| - [defaults setObject:nil forKey:keyHashInfo]; |
82 |
| - [defaults setObject:@(YES) forKey:KeyPackageUpdatedMarked]; |
83 |
| - |
84 |
| - // ...need clear files later |
85 |
| - } |
86 |
| - else { |
87 | 96 | NSString *curVersion = pushyInfo[paramCurrentVersion];
|
88 | 97 |
|
89 | 98 | BOOL isFirstTime = [pushyInfo[paramIsFirstTime] boolValue];
|
@@ -127,13 +136,11 @@ + (NSString *) rollback {
|
127 | 136 | NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
|
128 | 137 | NSString *lastVersion = pushyInfo[paramLastVersion];
|
129 | 138 | NSString *curVersion = pushyInfo[paramCurrentVersion];
|
130 |
| - NSString *curPackageVersion = [RCTPushy packageVersion]; |
131 | 139 | if (lastVersion.length) {
|
132 | 140 | // roll back to last version
|
133 | 141 | [defaults setObject:@{paramCurrentVersion:lastVersion,
|
134 | 142 | paramIsFirstTime:@(NO),
|
135 |
| - paramIsFirstLoadOk:@(YES), |
136 |
| - paramPackageVersion:curPackageVersion} |
| 143 | + paramIsFirstLoadOk:@(YES)} |
137 | 144 | forKey:keyPushyInfo];
|
138 | 145 | }
|
139 | 146 | else {
|
@@ -296,7 +303,6 @@ - (instancetype)init
|
296 | 303 | newInfo[paramLastVersion] = lastVersion;
|
297 | 304 | newInfo[paramIsFirstTime] = @(YES);
|
298 | 305 | newInfo[paramIsFirstLoadOk] = @(NO);
|
299 |
| - newInfo[paramPackageVersion] = [RCTPushy packageVersion]; |
300 | 306 | [defaults setObject:newInfo forKey:keyPushyInfo];
|
301 | 307 |
|
302 | 308 |
|
|
0 commit comments