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

Do not show privacy screen when app is in foreground while inactive #30

Open
wants to merge 2 commits 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
31 changes: 18 additions & 13 deletions src/ios/PrivacyScreenPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ @implementation PrivacyScreenPlugin

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

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

- (void)onAppDidBecomeActive:(UIApplication *)application
- (void)onAppWillEnterForeground:(UIApplication *)application
{
if (imageView == NULL) {
self.viewController.view.window.hidden = NO;
Expand All @@ -28,7 +28,7 @@ - (void)onAppDidBecomeActive:(UIApplication *)application
}
}

- (void)onAppWillResignActive:(UIApplication *)application
- (void)onAppDidEnterBackground:(UIApplication *)application
{
CDVViewController *vc = (CDVViewController*)self.viewController;
NSString *imgName = [self getImageName:self.viewController.interfaceOrientation delegate:(id<CDVScreenOrientationDelegate>)vc device:[self getCurrentDevice]];
Expand All @@ -37,7 +37,8 @@ - (void)onAppWillResignActive:(UIApplication *)application
imageView = NULL;
self.viewController.view.window.hidden = YES;
} else {
imageView = [[UIImageView alloc]initWithFrame:[self.viewController.view bounds]];
imageView = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[imageView setImage:splash];

#ifdef __CORDOVA_4_0_0
Expand Down Expand Up @@ -79,6 +80,10 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
// Use UILaunchImageFile if specified in plist. Otherwise, use Default.
NSString* imageName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchImageFile"];

if (imageName == nil && [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchImages"] != nil){
imageName = @"LaunchImage";
}

NSUInteger supportedOrientations = [orientationDelegate supportedInterfaceOrientations];

// Checks to see if the developer has locked the orientation to use only one of Portrait or Landscape
Expand Down Expand Up @@ -111,11 +116,11 @@ - (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
imageName = isLandscape ? nil : [imageName stringByAppendingString:@"-667h"];
} else if (device.iPhone6Plus) { // supports landscape
if (device.iPhone5) { // does not support landscape, so use landscape image instead of showing a black screen
imageName = [imageName stringByAppendingString:@"-568h"];
} else if (device.iPhone6) { // does not support landscape, so use landscape image instead of showing a black screen
imageName = [imageName stringByAppendingString:@"-667h"];
} else if (device.iPhone6Plus) { // supports landscape
if (isOrientationLocked) {
imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"")];
} else {
Expand Down Expand Up @@ -152,4 +157,4 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
return imageName;
}

@end
@end