|
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 |
| 14 | +// Taken from https://github.com/phonegap-build/PushPlugin/blob/master/src/ios/AppDelegate%2Bnotification.m |
15 | 15 | // its dangerous to override a method from within a category. |
16 | 16 | // Instead we will use method swizzling. we set this up in the load call. |
17 | 17 | + (void)load |
18 | 18 | { |
19 | 19 | Method original, swizzled; |
20 | | - |
| 20 | + |
21 | 21 | original = class_getInstanceMethod(self, @selector(init)); |
22 | 22 | swizzled = class_getInstanceMethod(self, @selector(swizzled_init)); |
23 | 23 | method_exchangeImplementations(original, swizzled); |
24 | 24 | } |
25 | 25 |
|
26 | 26 | - (AppDelegate *)swizzled_init |
27 | 27 | { |
28 | | - [[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch]; |
29 | | - // Add any notification observers here... |
30 | | - |
31 | | - // This actually calls the original init method over in AppDelegate. Equivilent to calling super |
32 | | - // on an overrided method, this is not recursive, although it appears that way. neat huh? |
33 | | - return [self swizzled_init]; |
| 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]; |
34 | 35 | } |
35 | 36 |
|
36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application |
37 | 38 | { |
38 | | - if (imageView == NULL) { |
39 | | - [[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch]; |
40 | | - self.window.hidden = NO; |
41 | | - } else { |
42 | | - [imageView removeFromSuperview]; |
43 | | - } |
| 39 | + if (imageView == NULL && [[UIApplication sharedApplication] respondsToSelector:@selector(ignoreSnapshotOnNextApplicationLaunch:)]) { |
| 40 | + [[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch]; |
| 41 | + self.window.hidden = NO; |
| 42 | + } else { |
| 43 | + [imageView removeFromSuperview]; |
| 44 | + } |
44 | 45 | } |
45 | 46 |
|
46 | 47 | - (void)applicationWillResignActive:(UIApplication *)application |
47 | 48 | { |
48 | | - // for now, assuming 'Default' is the basename of the splashscreen, with a fallback to hiding the window |
49 | | - UIImage *splash = [self imageNamedForDevice: @"Default"]; |
50 | | - if (splash == NULL) { |
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 | | - } |
| 49 | + // for now, assuming 'Default' is the basename of the splashscreen, with a fallback to hiding the window |
| 50 | + UIImage *splash = [self imageNamedForDevice: @"Default"]; |
| 51 | + if (splash == NULL && [[UIApplication sharedApplication] respondsToSelector:@selector(ignoreSnapshotOnNextApplicationLaunch:)]) { |
| 52 | + [[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch]; |
| 53 | + self.window.hidden = YES; |
| 54 | + } else { |
| 55 | + imageView = [[UIImageView alloc]initWithFrame:[self.window frame]]; |
| 56 | + [imageView setImage:splash]; |
| 57 | + [UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView]; |
| 58 | + } |
58 | 59 | } |
59 | 60 |
|
60 | 61 | - (UIImage*)imageNamedForDevice:(NSString*)name |
61 | 62 | { |
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"]; |
| 63 | + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { |
| 64 | + if (([UIScreen mainScreen].bounds.size.height * [UIScreen mainScreen].scale) >= 1136.0f) { |
| 65 | + name = [name stringByAppendingString:@"-568h@2x"]; |
| 66 | + } |
| 67 | + } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
| 68 | + name = [name stringByAppendingString:@"-Portrait"]; |
65 | 69 | } |
66 | | - } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
67 | | - name = [name stringByAppendingString:@"-Portrait"]; |
68 | | - } |
69 | | - return [UIImage imageNamed: name]; |
| 70 | + return [UIImage imageNamed: name]; |
70 | 71 | } |
71 | 72 |
|
72 | 73 | @end |
0 commit comments