From 559b300d29ba6eb2f951eb19b9bbf7ba9238a862 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Thu, 9 Apr 2015 14:07:18 -0700 Subject: [PATCH] CB-8836 - Crashes after animating splashscreen --- src/ios/CDVSplashScreen.m | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/ios/CDVSplashScreen.m b/src/ios/CDVSplashScreen.m index c28ae2f..3c0294b 100644 --- a/src/ios/CDVSplashScreen.m +++ b/src/ios/CDVSplashScreen.m @@ -289,19 +289,28 @@ } else if (fadeDuration == 0) { [self destroyViews]; } else { - [UIView transitionWithView:self.viewController.view - duration:fadeDuration - options:UIViewAnimationOptionTransitionNone - animations:^(void) { - [_imageView setAlpha:0]; - [_activityView setAlpha:0]; - } - completion:^(BOOL finished) { - if (finished) { - [self destroyViews]; - } - } - ]; + __weak __typeof(self) weakSelf = self; + + [UIView transitionWithView:self.viewController.view + duration:fadeDuration + options:UIViewAnimationOptionTransitionNone + animations:^(void) { + __typeof(self) strongSelf = weakSelf; + if (strongSelf != nil) { + dispatch_async(dispatch_get_main_queue(), ^{ + [strongSelf->_activityView setAlpha:0]; + [strongSelf->_imageView setAlpha:0]; + }); + } + } + completion:^(BOOL finished) { + if (finished) { + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf destroyViews]; + }); + } + } + ]; } }