Skip to content

Commit 9b596ef

Browse files
iOS shows splashscreen instead of a black screen in case splashscreens adhere to certain naming conventions (could be tweaked a bit further)
1 parent 84655b2 commit 9b596ef

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/ios/AppDelegate+privacyscreen.m

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#import "AppDelegate+privacyscreen.h"
88
#import <objc/runtime.h>
99

10+
UIImageView *imageView;
11+
1012
@implementation AppDelegate (privacyscreen)
1113

1214
// Taken from https://github.com/phonegap-build/PushPlugin/blob/master/src/ios/AppDelegate%2Bnotification.m
@@ -33,14 +35,38 @@ - (AppDelegate *)swizzled_init
3335

3436
- (void)applicationDidBecomeActive:(UIApplication *)application
3537
{
36-
[[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch];
37-
self.window.hidden = NO;
38+
if (imageView == NULL) {
39+
[[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch];
40+
self.window.hidden = NO;
41+
} else {
42+
[imageView removeFromSuperview];
43+
}
3844
}
3945

4046
- (void)applicationWillResignActive:(UIApplication *)application
4147
{
42-
[[UIApplication sharedApplication] ignoreSnapshotOnNextApplicationLaunch];
43-
self.window.hidden = YES;
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+
}
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];
4470
}
4571

4672
@end

0 commit comments

Comments
 (0)