Skip to content
Permalink
Browse files
Fix crash on iOS when reloading page from remote Safari
 This closes #110
  • Loading branch information
bugnano authored and jcesarmobile committed Jul 21, 2016
1 parent d65c0c7 commit 0a8b5be3d1f78ef699c5ed6db1b964649fe7f582
Showing 1 changed file with 21 additions and 13 deletions.
@@ -77,7 +77,7 @@ - (void)createViews
BOOL autorotateValue = (device.iPad || device.iPhone6Plus) ?
[(CDVViewController *)self.viewController shouldAutorotateDefaultValue] :
NO;

[(CDVViewController *)self.viewController setEnabledAutorotation:autorotateValue];

NSString* topActivityIndicator = [self.commandDelegate.settings objectForKey:[@"TopActivityIndicator" lowercaseString]];
@@ -142,20 +142,28 @@ - (void)destroyViews
_curImageName = nil;

self.viewController.view.userInteractionEnabled = YES; // re-enable user interaction upon completion
[self.viewController.view removeObserver:self forKeyPath:@"frame"];
[self.viewController.view removeObserver:self forKeyPath:@"bounds"];
@try {
[self.viewController.view removeObserver:self forKeyPath:@"frame"];
[self.viewController.view removeObserver:self forKeyPath:@"bounds"];
}
@catch (NSException *exception) {
// When reloading the page from a remotely connected Safari, there
// are no observers, so the removeObserver method throws an exception,
// that we can safely ignore.
// Alternatively we can check whether there are observers before calling removeObserver
}
}

- (CDV_iOSDevice) getCurrentDevice
{
CDV_iOSDevice device;

UIScreen* mainScreen = [UIScreen mainScreen];
CGFloat mainScreenHeight = mainScreen.bounds.size.height;
CGFloat mainScreenWidth = mainScreen.bounds.size.width;

int limit = MAX(mainScreenHeight,mainScreenWidth);

device.iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
device.iPhone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
device.retina = ([mainScreen scale] == 2.0);
@@ -166,23 +174,23 @@ - (CDV_iOSDevice) getCurrentDevice
// this is appropriate for detecting the runtime screen environment
device.iPhone6 = (device.iPhone && limit == 667.0);
device.iPhone6Plus = (device.iPhone && limit == 736.0);

return device;
}

- (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(id<CDVScreenOrientationDelegate>)orientationDelegate device:(CDV_iOSDevice)device
{
// Use UILaunchImageFile if specified in plist. Otherwise, use Default.
NSString* imageName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchImageFile"];

NSUInteger supportedOrientations = [orientationDelegate supportedInterfaceOrientations];

// Checks to see if the developer has locked the orientation to use only one of Portrait or Landscape
BOOL supportsLandscape = (supportedOrientations & UIInterfaceOrientationMaskLandscape);
BOOL supportsPortrait = (supportedOrientations & UIInterfaceOrientationMaskPortrait || supportedOrientations & UIInterfaceOrientationMaskPortraitUpsideDown);
// this means there are no mixed orientations in there
BOOL isOrientationLocked = !(supportsPortrait && supportsLandscape);

if (imageName)
{
imageName = [imageName stringByDeletingPathExtension];
@@ -251,7 +259,7 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
case UIInterfaceOrientationLandscapeRight:
imageName = [imageName stringByAppendingString:@"-Landscape"];
break;

case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
default:
@@ -260,7 +268,7 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
}
}
}

return imageName;
}

@@ -457,7 +465,7 @@ - (void)setVisible:(BOOL)visible andForce:(BOOL)force
[weakSelf hideViews];
}
completion:^(BOOL finished) {
// Always destroy views, otherwise you could have an
// Always destroy views, otherwise you could have an
// invisible splashscreen that is overlayed over your active views
// which causes that no touch events are passed
if (!_destroyed) {

0 comments on commit 0a8b5be

Please sign in to comment.