Skip to content
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