1#import <MBProgressHUD/MBProgressHUD.h>
2
3#import "EXManagedAppSplashScreenViewController.h"
4#import "EXSplashScreenHUDButton.h"
5
6@interface EXManagedAppSplashScreenViewController()
7
8@property (nonatomic, weak) NSTimer *warningTimer;
9@property (nonatomic, weak) MBProgressHUD *warningHud;
10
11@end
12
13@implementation EXManagedAppSplashScreenViewController
14
15- (instancetype)initWithRootView:(UIView *)rootView splashScreenView:(UIView *)splashScreenView
16{
17  if (self = [super initWithRootView:rootView splashScreenView:splashScreenView]) {
18    self.splashScreenView.userInteractionEnabled = YES;
19  }
20
21  return self;
22}
23
24- (void)showWithCallback:(void (^)(void))successCallback failureCallback:(void (^)(NSString * _Nonnull))failureCallback
25{
26  [super showWithCallback:^{
27    [self startSplashScreenVisibleTimer];
28    if (successCallback) {
29      successCallback();
30    }
31  } failureCallback:failureCallback];
32}
33
34- (void)hideWithCallback:(void (^)(BOOL))successCallback failureCallback:(void (^)(NSString * _Nonnull))failureCallback
35{
36  [super hideWithCallback:^(BOOL isSuccess){
37    if (self.warningTimer) {
38      [self.warningTimer invalidate];
39    }
40
41    if (successCallback) {
42      successCallback(YES);
43    }
44  } failureCallback:failureCallback];
45}
46
47
48-(void)startSplashScreenVisibleTimer
49{
50  self.warningTimer = [NSTimer scheduledTimerWithTimeInterval:20.0
51                                                       target:self
52                                                     selector:@selector(showSplashScreenVisibleWarning)
53                                                     userInfo:nil
54                                                      repeats:NO];
55}
56
57- (void)showSplashScreenVisibleWarning
58{
59#if DEBUG
60  _warningHud = [MBProgressHUD showHUDAddedTo: self.splashScreenView animated:YES];
61  _warningHud.mode = MBProgressHUDModeCustomView;
62
63  EXSplashScreenHUDButton *button = [EXSplashScreenHUDButton buttonWithType: UIButtonTypeSystem];
64  [button addTarget:self action:@selector(navigateToFYI) forControlEvents:UIControlEventTouchUpInside];
65
66  _warningHud.customView = button;
67  _warningHud.offset = CGPointMake(0.f, MBProgressMaxOffset);
68
69  [_warningHud hideAnimated:YES afterDelay:8.f];
70#endif
71}
72
73- (void)navigateToFYI
74{
75  NSURL *fyiURL = [[NSURL alloc] initWithString:@"https://expo.fyi/splash-screen-hanging"];
76  [[UIApplication sharedApplication] openURL:fyiURL];
77  [_warningHud hideAnimated: YES];
78}
79
80@end
81