@@ -172,6 +172,29 @@ + (void)setUsingTestConfiguration:(BOOL)shouldUseTestConfiguration
172172@synthesize bridge = _bridge;
173173@synthesize methodQueue = _methodQueue;
174174
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+
175198/*
176199 * This method is used by the React Native bridge to allow
177200 * our plugin to expose constants to the JS-side. In our case
@@ -240,31 +263,16 @@ - (instancetype)init
240263 return self;
241264}
242265
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-
260266/*
261267 * This method is used when the app is started to either
262268 * initialize a pending update or rollback a faulty update
263269 * to the previous version.
264270 */
265271- (void )initializeUpdateAfterRestart
266272{
273+ #ifdef DEBUG
267274 [self clearDebugUpdates ];
275+ #endif
268276
269277 NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
270278 NSDictionary *pendingUpdate = [preferences objectForKey: PendingUpdateKey];
0 commit comments