@@ -172,6 +172,29 @@ + (void)setUsingTestConfiguration:(BOOL)shouldUseTestConfiguration
172
172
@synthesize bridge = _bridge;
173
173
@synthesize methodQueue = _methodQueue;
174
174
175
+ /*
176
+ * This method is used to clear updates that are installed
177
+ * under a different app version and hence don't apply anymore,
178
+ * during a debug run configuration and when the bridge is
179
+ * running the JS bundle from the dev server.
180
+ */
181
+ - (void )clearDebugUpdates
182
+ {
183
+ dispatch_async (dispatch_get_main_queue (), ^{
184
+ if ([_bridge.bundleURL.scheme hasPrefix: @" http" ]) {
185
+ NSError *error;
186
+ NSString *binaryAppVersion = [[CodePushConfig current ] appVersion ];
187
+ NSDictionary *currentPackageMetadata = [CodePushPackage getCurrentPackage: &error];
188
+ if (currentPackageMetadata) {
189
+ NSString *packageAppVersion = [currentPackageMetadata objectForKey: AppVersionKey];
190
+ if (![binaryAppVersion isEqualToString: packageAppVersion]) {
191
+ [CodePush clearUpdates ];
192
+ }
193
+ }
194
+ }
195
+ });
196
+ }
197
+
175
198
/*
176
199
* This method is used by the React Native bridge to allow
177
200
* our plugin to expose constants to the JS-side. In our case
@@ -240,31 +263,16 @@ - (instancetype)init
240
263
return self;
241
264
}
242
265
243
- - (void )clearDebugUpdates
244
- {
245
- dispatch_async (dispatch_get_main_queue (), ^{
246
- if ([_bridge.bundleURL.scheme hasPrefix: @" http" ]) {
247
- NSError *error;
248
- NSString *binaryAppVersion = [[CodePushConfig current ] appVersion ];
249
- NSDictionary *currentPackageMetadata = [CodePushPackage getCurrentPackage: &error];
250
- if (currentPackageMetadata) {
251
- NSString *packageAppVersion = [currentPackageMetadata objectForKey: AppVersionKey];
252
- if (![binaryAppVersion isEqualToString: packageAppVersion]) {
253
- [CodePush clearUpdates ];
254
- }
255
- }
256
- }
257
- });
258
- }
259
-
260
266
/*
261
267
* This method is used when the app is started to either
262
268
* initialize a pending update or rollback a faulty update
263
269
* to the previous version.
264
270
*/
265
271
- (void )initializeUpdateAfterRestart
266
272
{
273
+ #ifdef DEBUG
267
274
[self clearDebugUpdates ];
275
+ #endif
268
276
269
277
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
270
278
NSDictionary *pendingUpdate = [preferences objectForKey: PendingUpdateKey];
0 commit comments