Fix crash on iOS when reloading page from remote Safari

This closes #110
This commit is contained in:
Franco Bugnano 2016-07-21 17:14:42 +02:00 committed by Julio César
parent d65c0c7cc5
commit 0a8b5be3d1

View File

@ -77,7 +77,7 @@
BOOL autorotateValue = (device.iPad || device.iPhone6Plus) ? BOOL autorotateValue = (device.iPad || device.iPhone6Plus) ?
[(CDVViewController *)self.viewController shouldAutorotateDefaultValue] : [(CDVViewController *)self.viewController shouldAutorotateDefaultValue] :
NO; NO;
[(CDVViewController *)self.viewController setEnabledAutorotation:autorotateValue]; [(CDVViewController *)self.viewController setEnabledAutorotation:autorotateValue];
NSString* topActivityIndicator = [self.commandDelegate.settings objectForKey:[@"TopActivityIndicator" lowercaseString]]; NSString* topActivityIndicator = [self.commandDelegate.settings objectForKey:[@"TopActivityIndicator" lowercaseString]];
@ -142,20 +142,28 @@
_curImageName = nil; _curImageName = nil;
self.viewController.view.userInteractionEnabled = YES; // re-enable user interaction upon completion self.viewController.view.userInteractionEnabled = YES; // re-enable user interaction upon completion
[self.viewController.view removeObserver:self forKeyPath:@"frame"]; @try {
[self.viewController.view removeObserver:self forKeyPath:@"bounds"]; [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) getCurrentDevice
{ {
CDV_iOSDevice device; CDV_iOSDevice device;
UIScreen* mainScreen = [UIScreen mainScreen]; UIScreen* mainScreen = [UIScreen mainScreen];
CGFloat mainScreenHeight = mainScreen.bounds.size.height; CGFloat mainScreenHeight = mainScreen.bounds.size.height;
CGFloat mainScreenWidth = mainScreen.bounds.size.width; CGFloat mainScreenWidth = mainScreen.bounds.size.width;
int limit = MAX(mainScreenHeight,mainScreenWidth); int limit = MAX(mainScreenHeight,mainScreenWidth);
device.iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); device.iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
device.iPhone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone); device.iPhone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
device.retina = ([mainScreen scale] == 2.0); device.retina = ([mainScreen scale] == 2.0);
@ -166,7 +174,7 @@
// this is appropriate for detecting the runtime screen environment // this is appropriate for detecting the runtime screen environment
device.iPhone6 = (device.iPhone && limit == 667.0); device.iPhone6 = (device.iPhone && limit == 667.0);
device.iPhone6Plus = (device.iPhone && limit == 736.0); device.iPhone6Plus = (device.iPhone && limit == 736.0);
return device; return device;
} }
@ -174,15 +182,15 @@
{ {
// Use UILaunchImageFile if specified in plist. Otherwise, use Default. // Use UILaunchImageFile if specified in plist. Otherwise, use Default.
NSString* imageName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchImageFile"]; NSString* imageName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchImageFile"];
NSUInteger supportedOrientations = [orientationDelegate supportedInterfaceOrientations]; NSUInteger supportedOrientations = [orientationDelegate supportedInterfaceOrientations];
// Checks to see if the developer has locked the orientation to use only one of Portrait or Landscape // Checks to see if the developer has locked the orientation to use only one of Portrait or Landscape
BOOL supportsLandscape = (supportedOrientations & UIInterfaceOrientationMaskLandscape); BOOL supportsLandscape = (supportedOrientations & UIInterfaceOrientationMaskLandscape);
BOOL supportsPortrait = (supportedOrientations & UIInterfaceOrientationMaskPortrait || supportedOrientations & UIInterfaceOrientationMaskPortraitUpsideDown); BOOL supportsPortrait = (supportedOrientations & UIInterfaceOrientationMaskPortrait || supportedOrientations & UIInterfaceOrientationMaskPortraitUpsideDown);
// this means there are no mixed orientations in there // this means there are no mixed orientations in there
BOOL isOrientationLocked = !(supportsPortrait && supportsLandscape); BOOL isOrientationLocked = !(supportsPortrait && supportsLandscape);
if (imageName) if (imageName)
{ {
imageName = [imageName stringByDeletingPathExtension]; imageName = [imageName stringByDeletingPathExtension];
@ -251,7 +259,7 @@
case UIInterfaceOrientationLandscapeRight: case UIInterfaceOrientationLandscapeRight:
imageName = [imageName stringByAppendingString:@"-Landscape"]; imageName = [imageName stringByAppendingString:@"-Landscape"];
break; break;
case UIInterfaceOrientationPortrait: case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown: case UIInterfaceOrientationPortraitUpsideDown:
default: default:
@ -260,7 +268,7 @@
} }
} }
} }
return imageName; return imageName;
} }
@ -457,7 +465,7 @@
[weakSelf hideViews]; [weakSelf hideViews];
} }
completion:^(BOOL finished) { 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 // invisible splashscreen that is overlayed over your active views
// which causes that no touch events are passed // which causes that no touch events are passed
if (!_destroyed) { if (!_destroyed) {