Skip to content

Commit 0a2ec05

Browse files
committed
Add conditionals to support iOS 6
1 parent 138da47 commit 0a2ec05

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

src/ios/AppDelegate+privacyscreen.m

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,62 +11,63 @@
1111

1212
@implementation AppDelegate (privacyscreen)
1313

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
1515
// its dangerous to override a method from within a category.
1616
// Instead we will use method swizzling. we set this up in the load call.
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);
2424
}
2525

2626
- (AppDelegate *)swizzled_init
2727
{
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];
3435
}
3536

3637
- (void)applicationDidBecomeActive:(UIApplication *)application
3738
{
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+
}
4445
}
4546

4647
- (void)applicationWillResignActive:(UIApplication *)application
4748
{
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+
}
5859
}
5960

6061
- (UIImage*)imageNamedForDevice:(NSString*)name
6162
{
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"];
6569
}
66-
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
67-
name = [name stringByAppendingString:@"-Portrait"];
68-
}
69-
return [UIImage imageNamed: name];
70+
return [UIImage imageNamed: name];
7071
}
7172

7273
@end

0 commit comments

Comments
 (0)