Skip to content

Commit 19429d3

Browse files
#2 support landscape mode
1 parent 4b6b5e1 commit 19429d3

File tree

2 files changed

+23
-54
lines changed

2 files changed

+23
-54
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ This is a lovely feature for most apps, but if your app displays sensitive infor
77

88
This plugin flags your app so that it doesn't show your users' sensitive data in the task switcher. It sets the [FLAG_SECURE](http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SECURE) flag in Android (which also prevents manual screenshots from being taken) and hides the window in iOS.
99

10-
On iOS this plugin will try to show your splashscreen in the app switcher. If it fails to find a splashscreen, a black screen is shown instead.
10+
On iOS this plugin will try to show your splashscreen in the app switcher. It will search for splashscreens prefixed by `Default` or the value of the key `UILaunchImageFile` in your .plist file.
11+
If it fails to find a splashscreen for a specific device or orientation (portrait or landscape), a black screen is shown instead.
1112

1213
Installation
1314
------------

src/ios/AppDelegate+privacyscreen.m

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,31 @@
1111

1212
@implementation AppDelegate (privacyscreen)
1313

14-
// Taken from https://github.com/phonegap-build/PushPlugin/blob/master/src/ios/AppDelegate%2Bnotification.m
15-
// its dangerous to override a method from within a category.
16-
// Instead we will use method swizzling. we set this up in the load call.
17-
+ (void)load
18-
{
19-
Method original, swizzled;
20-
21-
original = class_getInstanceMethod(self, @selector(init));
22-
swizzled = class_getInstanceMethod(self, @selector(swizzled_init));
23-
method_exchangeImplementations(original, swizzled);
24-
}
25-
26-
- (AppDelegate *)swizzled_init
27-
{
28-
if ([UIApplication respondsToSelector:@selector(ignoreSnapshotOnNextApplicationLaunch:)]) {
29-
[[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch];
30-
// Add any notification observers here...
31-
}
32-
// This actually calls the original init method over in AppDelegate. Equivilent to calling super
33-
// on an overrided method, this is not recursive, although it appears that way. neat huh?
34-
return [self swizzled_init];
35-
}
36-
3714
- (void)applicationDidBecomeActive:(UIApplication *)application
3815
{
39-
if (imageView == NULL && [[UIApplication sharedApplication] respondsToSelector:@selector(ignoreSnapshotOnNextApplicationLaunch:)]) {
40-
[[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch];
41-
self.window.hidden = NO;
42-
} else {
43-
[imageView removeFromSuperview];
44-
}
16+
if (imageView == NULL) {
17+
self.window.hidden = NO;
18+
} else {
19+
[imageView removeFromSuperview];
20+
}
4521
}
4622

4723
- (void)applicationWillResignActive:(UIApplication *)application
4824
{
49-
UIImage *splash = [UIImage imageNamed:[self getImageName:self.viewController.interfaceOrientation delegate:(id<CDVScreenOrientationDelegate>)self.viewController device:[self getCurrentDevice]]];
50-
if (splash == NULL && [[UIApplication sharedApplication] respondsToSelector:@selector(ignoreSnapshotOnNextApplicationLaunch:)]) {
51-
[[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch];
52-
self.window.hidden = YES;
53-
} else {
54-
imageView = [[UIImageView alloc]initWithFrame:[self.window frame]];
55-
[imageView setImage:splash];
56-
[UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView];
57-
}
58-
}
59-
60-
- (UIImage*)imageNamedForDevice:(NSString*)name
61-
{
62-
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
63-
if (([UIScreen mainScreen].bounds.size.height * [UIScreen mainScreen].scale) >= 1136.0f) {
64-
name = [name stringByAppendingString:@"-568h@2x"];
65-
}
66-
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
67-
name = [name stringByAppendingString:@"-Portrait"];
68-
}
69-
return [UIImage imageNamed: name];
25+
NSString *imgName = [self getImageName:self.viewController.interfaceOrientation delegate:(id<CDVScreenOrientationDelegate>)self.viewController device:[self getCurrentDevice]];
26+
UIImage *splash = [UIImage imageNamed:imgName];
27+
if (splash == NULL) {
28+
self.window.hidden = YES;
29+
imageView = NULL;
30+
} else {
31+
imageView = [[UIImageView alloc]initWithFrame:[self.window frame]];
32+
[imageView setImage:splash];
33+
[UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView];
34+
}
7035
}
7136

72-
7337
// Code below borrowed from the CDV splashscreen plugin (https://github.com/apache/cordova-plugin-splashscreen)
38+
// Made some adjustments though, because landscape splashscreens are not available for iphone < 6 plus
7439
- (CDV_iOSDevice) getCurrentDevice
7540
{
7641
CDV_iOSDevice device;
@@ -113,10 +78,13 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
11378
imageName = @"Default";
11479
}
11580

81+
BOOL isLandscape = supportsLandscape &&
82+
(currentOrientation == UIInterfaceOrientationLandscapeLeft || currentOrientation == UIInterfaceOrientationLandscapeRight);
83+
11684
if (device.iPhone5) { // does not support landscape
117-
imageName = [imageName stringByAppendingString:@"-568h"];
85+
imageName = isLandscape ? nil : [imageName stringByAppendingString:@"-568h"];
11886
} else if (device.iPhone6) { // does not support landscape
119-
imageName = [imageName stringByAppendingString:@"-667h"];
87+
imageName = isLandscape ? nil : [imageName stringByAppendingString:@"-667h"];
12088
} else if (device.iPhone6Plus) { // supports landscape
12189
if (isOrientationLocked) {
12290
imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"")];

0 commit comments

Comments
 (0)