Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(ios) Fix bug where ios was displaying splash screen over touch id #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 7 additions & 31 deletions src/ios/PrivacyScreenPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,49 @@
* MIT Licensed
*/
#import "PrivacyScreenPlugin.h"

static UIImageView *imageView;

UIImageView *imageView;
@implementation PrivacyScreenPlugin

- (void)pluginInitialize
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil];
name:UIApplicationDidEnterBackgroundNotification object:nil];
}

- (void)onAppDidBecomeActive:(UIApplication *)application
- (void)applicationWillEnterForeground:(UIApplication *)application
{
if (imageView == NULL) {
self.viewController.view.window.hidden = NO;
} else {
[imageView removeFromSuperview];
}
}

- (void)onAppWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
{
CDVViewController *vc = (CDVViewController*)self.viewController;
NSString *imgName = [self getImageName:self.viewController.interfaceOrientation delegate:(id<CDVScreenOrientationDelegate>)vc device:[self getCurrentDevice]];
UIImage *splash = [UIImage imageNamed:imgName];
if (splash == NULL) {
imageView = NULL;
self.viewController.view.window.hidden = YES;
} else {
imageView = [[UIImageView alloc]initWithFrame:[self.viewController.view bounds]];
[imageView setImage:splash];

#ifdef __CORDOVA_4_0_0
[[UIApplication sharedApplication].keyWindow addSubview:imageView];
#else
[self.viewController.view addSubview:imageView];
#endif
}
}

// Code below borrowed from the CDV splashscreen plugin @ https://github.com/apache/cordova-plugin-splashscreen
// Made some adjustments though, becuase landscape splashscreens are not available for iphone < 6 plus
- (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);
Expand All @@ -70,29 +58,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];
} else {
imageName = @"Default";
}

// Add Asset Catalog specific prefixes
if ([imageName isEqualToString:@"LaunchImage"])
{
Expand All @@ -107,10 +89,8 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
}
}
}

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
Expand All @@ -129,7 +109,6 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
}
}
imageName = [imageName stringByAppendingString:@"-736h"];

} else if (device.iPad) { // supports landscape
if (isOrientationLocked) {
imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"-Portrait")];
Expand All @@ -139,7 +118,6 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
case UIInterfaceOrientationLandscapeRight:
imageName = [imageName stringByAppendingString:@"-Landscape"];
break;

case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
default:
Expand All @@ -148,8 +126,6 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
}
}
}

return imageName;
}

@end
@end