|
11 | 11 |
|
12 | 12 | @implementation AppDelegate (privacyscreen) |
13 | 13 |
|
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 | | - |
37 | 14 | - (void)applicationDidBecomeActive:(UIApplication *)application |
38 | 15 | { |
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 | + } |
45 | 21 | } |
46 | 22 |
|
47 | 23 | - (void)applicationWillResignActive:(UIApplication *)application |
48 | 24 | { |
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 | + } |
70 | 35 | } |
71 | 36 |
|
72 | | - |
73 | 37 | // 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 |
74 | 39 | - (CDV_iOSDevice) getCurrentDevice |
75 | 40 | { |
76 | 41 | CDV_iOSDevice device; |
@@ -113,10 +78,13 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i |
113 | 78 | imageName = @"Default"; |
114 | 79 | } |
115 | 80 |
|
| 81 | + BOOL isLandscape = supportsLandscape && |
| 82 | + (currentOrientation == UIInterfaceOrientationLandscapeLeft || currentOrientation == UIInterfaceOrientationLandscapeRight); |
| 83 | + |
116 | 84 | if (device.iPhone5) { // does not support landscape |
117 | | - imageName = [imageName stringByAppendingString:@"-568h"]; |
| 85 | + imageName = isLandscape ? nil : [imageName stringByAppendingString:@"-568h"]; |
118 | 86 | } else if (device.iPhone6) { // does not support landscape |
119 | | - imageName = [imageName stringByAppendingString:@"-667h"]; |
| 87 | + imageName = isLandscape ? nil : [imageName stringByAppendingString:@"-667h"]; |
120 | 88 | } else if (device.iPhone6Plus) { // supports landscape |
121 | 89 | if (isOrientationLocked) { |
122 | 90 | imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"")]; |
|
0 commit comments