From 78e6422e026ebd46cf1bf29adb588819c290aed0 Mon Sep 17 00:00:00 2001 From: iryna-kovalchuk Date: Tue, 5 Jun 2018 17:19:37 +0300 Subject: [PATCH] add iphone X support --- src/ios/PrivacyScreenPlugin.h | 1 + src/ios/PrivacyScreenPlugin.m | 134 ++++++++++++++++++++-------------- 2 files changed, 80 insertions(+), 55 deletions(-) diff --git a/src/ios/PrivacyScreenPlugin.h b/src/ios/PrivacyScreenPlugin.h index 6ce5c3a..7b86c65 100644 --- a/src/ios/PrivacyScreenPlugin.h +++ b/src/ios/PrivacyScreenPlugin.h @@ -14,6 +14,7 @@ typedef struct { BOOL iPhone5; BOOL iPhone6; BOOL iPhone6Plus; + BOOL iPhoneX; BOOL retina; } CDV_iOSDevice; diff --git a/src/ios/PrivacyScreenPlugin.m b/src/ios/PrivacyScreenPlugin.m index 67303ee..4f6fe1f 100644 --- a/src/ios/PrivacyScreenPlugin.m +++ b/src/ios/PrivacyScreenPlugin.m @@ -39,7 +39,7 @@ - (void)onAppWillResignActive:(UIApplication *)application } else { imageView = [[UIImageView alloc]initWithFrame:[self.viewController.view bounds]]; [imageView setImage:splash]; - + #ifdef __CORDOVA_4_0_0 [[UIApplication sharedApplication].keyWindow addSubview:imageView]; #else @@ -53,13 +53,13 @@ - (void)onAppWillResignActive:(UIApplication *)application - (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); @@ -70,7 +70,8 @@ - (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); - + device.iPhoneX = (device.iPhone && limit == 812.0); + return device; } @@ -78,15 +79,15 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i { // 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]; } else { @@ -96,60 +97,83 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i // Add Asset Catalog specific prefixes if ([imageName isEqualToString:@"LaunchImage"]) { - if(device.iPhone4 || device.iPhone5 || device.iPad) { - imageName = [imageName stringByAppendingString:@"-700"]; - } else if(device.iPhone6) { - imageName = [imageName stringByAppendingString:@"-800"]; - } else if(device.iPhone6Plus) { - imageName = [imageName stringByAppendingString:@"-800"]; - if (currentOrientation == UIInterfaceOrientationPortrait || currentOrientation == UIInterfaceOrientationPortraitUpsideDown) { - imageName = [imageName stringByAppendingString:@"-Portrait"]; + if (device.iPhone4 || device.iPhone5 || device.iPad) { + imageName = [imageName stringByAppendingString:@"-700"]; + } else if(device.iPhone6) { + imageName = [imageName stringByAppendingString:@"-800"]; + } else if(device.iPhone6Plus || device.iPhoneX) { + if(device.iPhone6Plus) { + imageName = [imageName stringByAppendingString:@"-800"]; + } else { + imageName = [imageName stringByAppendingString:@"-1100"]; + } + if (currentOrientation == UIInterfaceOrientationPortrait || currentOrientation == UIInterfaceOrientationPortraitUpsideDown) + { + imageName = [imageName stringByAppendingString:@"-Portrait"]; + } } - } } - + BOOL isLandscape = supportsLandscape && (currentOrientation == UIInterfaceOrientationLandscapeLeft || currentOrientation == UIInterfaceOrientationLandscapeRight); - - if (device.iPhone5) { // does not support landscape - imageName = isLandscape ? nil : [imageName stringByAppendingString:@"-568h"]; - } else if (device.iPhone6) { // does not support landscape - imageName = isLandscape ? nil : [imageName stringByAppendingString:@"-667h"]; - } else if (device.iPhone6Plus) { // supports landscape - if (isOrientationLocked) { - imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"")]; - } else { - switch (currentOrientation) { - case UIInterfaceOrientationLandscapeLeft: - case UIInterfaceOrientationLandscapeRight: - imageName = [imageName stringByAppendingString:@"-Landscape"]; - break; - default: - break; + + if (device.iPhone5) + { // does not support landscape + imageName = [imageName stringByAppendingString:@"-568h"]; + } + else if (device.iPhone6) + { // does not support landscape + imageName = [imageName stringByAppendingString:@"-667h"]; + } + else if (device.iPhone6Plus || device.iPhoneX) + { // supports landscape + if (isOrientationLocked) + { + imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"")]; } - } - imageName = [imageName stringByAppendingString:@"-736h"]; - - } else if (device.iPad) { // supports landscape - if (isOrientationLocked) { - imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"-Portrait")]; - } else { - switch (currentOrientation) { - case UIInterfaceOrientationLandscapeLeft: - case UIInterfaceOrientationLandscapeRight: - imageName = [imageName stringByAppendingString:@"-Landscape"]; - break; - - case UIInterfaceOrientationPortrait: - case UIInterfaceOrientationPortraitUpsideDown: - default: - imageName = [imageName stringByAppendingString:@"-Portrait"]; - break; + else + { + switch (currentOrientation) + { + case UIInterfaceOrientationLandscapeLeft: + case UIInterfaceOrientationLandscapeRight: + imageName = [imageName stringByAppendingString:@"-Landscape"]; + break; + default: + break; + } + } + if (device.iPhoneX) { + imageName = [imageName stringByAppendingString:@"-2436h"]; + } else { + imageName = [imageName stringByAppendingString:@"-736h"]; } - } } - + else if (device.iPad) + { // supports landscape + if (isOrientationLocked) + { + imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"-Portrait")]; + } + else + { + switch (currentOrientation) + { + case UIInterfaceOrientationLandscapeLeft: + case UIInterfaceOrientationLandscapeRight: + imageName = [imageName stringByAppendingString:@"-Landscape"]; + break; + + case UIInterfaceOrientationPortrait: + case UIInterfaceOrientationPortraitUpsideDown: + default: + imageName = [imageName stringByAppendingString:@"-Portrait"]; + break; + } + } + } + return imageName; } -@end \ No newline at end of file +@end