Skip to content

Commit 4b6b5e1

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

File tree

4 files changed

+103
-9
lines changed

4 files changed

+103
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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 show your splashscreen in the app switcher, but it requires your splashscreens basesname to be named `Default`. E.g. `Default~iphone.png` and `Default-568@2x~iphone.png`.
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.
1111

1212
Installation
1313
------------

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="org.devgeeks.privacyscreen" version="0.0.5">
2+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="org.devgeeks.privacyscreen" version="0.0.6">
33

44
<name>PrivacyScreenPlugin</name>
55
<description>Secures your app from displaying a screenshot in task switchers under Android and iOS. Keeps sensitive information private.</description>

src/ios/AppDelegate+privacyscreen.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@
66
*/
77
#import "AppDelegate.h"
88

9+
typedef struct {
10+
BOOL iPhone;
11+
BOOL iPad;
12+
BOOL iPhone5;
13+
BOOL iPhone6;
14+
BOOL iPhone6Plus;
15+
BOOL retina;
16+
17+
} CDV_iOSDevice;
18+
919
@interface AppDelegate (privacyscreen)
10-
- (void)applicationWillResignActive:(UIApplication *)application;
11-
- (void)applicationDidBecomeActive:(UIApplication *)application;
20+
- (void)applicationWillResignActive:(UIApplication *)application;
21+
- (void)applicationDidBecomeActive:(UIApplication *)application;
1222

13-
@end
23+
@end

src/ios/AppDelegate+privacyscreen.m

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ @implementation AppDelegate (privacyscreen)
1717
+ (void)load
1818
{
1919
Method original, swizzled;
20-
20+
2121
original = class_getInstanceMethod(self, @selector(init));
2222
swizzled = class_getInstanceMethod(self, @selector(swizzled_init));
2323
method_exchangeImplementations(original, swizzled);
@@ -46,8 +46,7 @@ - (void)applicationDidBecomeActive:(UIApplication *)application
4646

4747
- (void)applicationWillResignActive:(UIApplication *)application
4848
{
49-
// for now, assuming 'Default' is the basename of the splashscreen, with a fallback to hiding the window
50-
UIImage *splash = [self imageNamedForDevice: @"Default"];
49+
UIImage *splash = [UIImage imageNamed:[self getImageName:self.viewController.interfaceOrientation delegate:(id<CDVScreenOrientationDelegate>)self.viewController device:[self getCurrentDevice]]];
5150
if (splash == NULL && [[UIApplication sharedApplication] respondsToSelector:@selector(ignoreSnapshotOnNextApplicationLaunch:)]) {
5251
[[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch];
5352
self.window.hidden = YES;
@@ -70,4 +69,89 @@ - (UIImage*)imageNamedForDevice:(NSString*)name
7069
return [UIImage imageNamed: name];
7170
}
7271

73-
@end
72+
73+
// Code below borrowed from the CDV splashscreen plugin (https://github.com/apache/cordova-plugin-splashscreen)
74+
- (CDV_iOSDevice) getCurrentDevice
75+
{
76+
CDV_iOSDevice device;
77+
78+
UIScreen* mainScreen = [UIScreen mainScreen];
79+
CGFloat mainScreenHeight = mainScreen.bounds.size.height;
80+
CGFloat mainScreenWidth = mainScreen.bounds.size.width;
81+
82+
int limit = MAX(mainScreenHeight,mainScreenWidth);
83+
84+
device.iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
85+
device.iPhone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
86+
device.retina = ([mainScreen scale] == 2.0);
87+
device.iPhone5 = (device.iPhone && limit == 568.0);
88+
// note these below is not a true device detect, for example if you are on an
89+
// iPhone 6/6+ but the app is scaled it will prob set iPhone5 as true, but
90+
// this is appropriate for detecting the runtime screen environment
91+
device.iPhone6 = (device.iPhone && limit == 667.0);
92+
device.iPhone6Plus = (device.iPhone && limit == 736.0);
93+
94+
return device;
95+
}
96+
97+
- (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(id<CDVScreenOrientationDelegate>)orientationDelegate device:(CDV_iOSDevice)device
98+
{
99+
// Use UILaunchImageFile if specified in plist. Otherwise, use Default.
100+
NSString* imageName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchImageFile"];
101+
102+
NSUInteger supportedOrientations = [orientationDelegate supportedInterfaceOrientations];
103+
104+
// Checks to see if the developer has locked the orientation to use only one of Portrait or Landscape
105+
BOOL supportsLandscape = (supportedOrientations & UIInterfaceOrientationMaskLandscape);
106+
BOOL supportsPortrait = (supportedOrientations & UIInterfaceOrientationMaskPortrait || supportedOrientations & UIInterfaceOrientationMaskPortraitUpsideDown);
107+
// this means there are no mixed orientations in there
108+
BOOL isOrientationLocked = !(supportsPortrait && supportsLandscape);
109+
110+
if (imageName) {
111+
imageName = [imageName stringByDeletingPathExtension];
112+
} else {
113+
imageName = @"Default";
114+
}
115+
116+
if (device.iPhone5) { // does not support landscape
117+
imageName = [imageName stringByAppendingString:@"-568h"];
118+
} else if (device.iPhone6) { // does not support landscape
119+
imageName = [imageName stringByAppendingString:@"-667h"];
120+
} else if (device.iPhone6Plus) { // supports landscape
121+
if (isOrientationLocked) {
122+
imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"")];
123+
} else {
124+
switch (currentOrientation) {
125+
case UIInterfaceOrientationLandscapeLeft:
126+
case UIInterfaceOrientationLandscapeRight:
127+
imageName = [imageName stringByAppendingString:@"-Landscape"];
128+
break;
129+
default:
130+
break;
131+
}
132+
}
133+
imageName = [imageName stringByAppendingString:@"-736h"];
134+
135+
} else if (device.iPad) { // supports landscape
136+
if (isOrientationLocked) {
137+
imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"-Portrait")];
138+
} else {
139+
switch (currentOrientation) {
140+
case UIInterfaceOrientationLandscapeLeft:
141+
case UIInterfaceOrientationLandscapeRight:
142+
imageName = [imageName stringByAppendingString:@"-Landscape"];
143+
break;
144+
145+
case UIInterfaceOrientationPortrait:
146+
case UIInterfaceOrientationPortraitUpsideDown:
147+
default:
148+
imageName = [imageName stringByAppendingString:@"-Portrait"];
149+
break;
150+
}
151+
}
152+
}
153+
154+
return imageName;
155+
}
156+
157+
@end

0 commit comments

Comments
 (0)