1*be199093STomasz Sapeta#import <MBProgressHUD/MBProgressHUD.h> 2*be199093STomasz Sapeta 39fcddb20Sandy#import "EXManagedAppSplashScreenViewController.h" 49fcddb20Sandy#import "EXSplashScreenHUDButton.h" 59fcddb20Sandy 69fcddb20Sandy@interface EXManagedAppSplashScreenViewController() 79fcddb20Sandy 89fcddb20Sandy@property (nonatomic, weak) NSTimer *warningTimer; 99fcddb20Sandy@property (nonatomic, weak) MBProgressHUD *warningHud; 109fcddb20Sandy 119fcddb20Sandy@end 129fcddb20Sandy 139fcddb20Sandy@implementation EXManagedAppSplashScreenViewController 149fcddb20Sandy 159fcddb20Sandy- (instancetype)initWithRootView:(UIView *)rootView splashScreenView:(UIView *)splashScreenView 169fcddb20Sandy{ 179fcddb20Sandy if (self = [super initWithRootView:rootView splashScreenView:splashScreenView]) { 189fcddb20Sandy self.splashScreenView.userInteractionEnabled = YES; 199fcddb20Sandy } 209fcddb20Sandy 219fcddb20Sandy return self; 229fcddb20Sandy} 239fcddb20Sandy 249fcddb20Sandy- (void)showWithCallback:(void (^)(void))successCallback failureCallback:(void (^)(NSString * _Nonnull))failureCallback 259fcddb20Sandy{ 269fcddb20Sandy [super showWithCallback:^{ 279fcddb20Sandy if (successCallback) { 289fcddb20Sandy successCallback(); 299fcddb20Sandy } 309fcddb20Sandy } failureCallback:failureCallback]; 319fcddb20Sandy} 329fcddb20Sandy 339fcddb20Sandy- (void)hideWithCallback:(void (^)(BOOL))successCallback failureCallback:(void (^)(NSString * _Nonnull))failureCallback 349fcddb20Sandy{ 359fcddb20Sandy [super hideWithCallback:^(BOOL isSuccess){ 369fcddb20Sandy if (self.warningTimer) { 379fcddb20Sandy [self.warningTimer invalidate]; 389fcddb20Sandy } 399fcddb20Sandy 409fcddb20Sandy if (successCallback) { 419fcddb20Sandy successCallback(YES); 429fcddb20Sandy } 439fcddb20Sandy } failureCallback:failureCallback]; 449fcddb20Sandy} 459fcddb20Sandy 469fcddb20Sandy 479fcddb20Sandy-(void)startSplashScreenVisibleTimer 489fcddb20Sandy{ 499fcddb20Sandy self.warningTimer = [NSTimer scheduledTimerWithTimeInterval:20.0 509fcddb20Sandy target:self 519fcddb20Sandy selector:@selector(showSplashScreenVisibleWarning) 529fcddb20Sandy userInfo:nil 539fcddb20Sandy repeats:NO]; 549fcddb20Sandy} 559fcddb20Sandy 569fcddb20Sandy- (void)showSplashScreenVisibleWarning 579fcddb20Sandy{ 589fcddb20Sandy#if DEBUG 599fcddb20Sandy _warningHud = [MBProgressHUD showHUDAddedTo: self.splashScreenView animated:YES]; 609fcddb20Sandy _warningHud.mode = MBProgressHUDModeCustomView; 619fcddb20Sandy 629fcddb20Sandy EXSplashScreenHUDButton *button = [EXSplashScreenHUDButton buttonWithType: UIButtonTypeSystem]; 639fcddb20Sandy [button addTarget:self action:@selector(navigateToFYI) forControlEvents:UIControlEventTouchUpInside]; 649fcddb20Sandy 659fcddb20Sandy _warningHud.customView = button; 669fcddb20Sandy _warningHud.offset = CGPointMake(0.f, MBProgressMaxOffset); 679fcddb20Sandy 689fcddb20Sandy [_warningHud hideAnimated:YES afterDelay:8.f]; 699fcddb20Sandy#endif 709fcddb20Sandy} 719fcddb20Sandy 729fcddb20Sandy- (void)navigateToFYI 739fcddb20Sandy{ 749fcddb20Sandy NSURL *fyiURL = [[NSURL alloc] initWithString:@"https://expo.fyi/splash-screen-hanging"]; 759fcddb20Sandy [[UIApplication sharedApplication] openURL:fyiURL]; 769fcddb20Sandy [_warningHud hideAnimated: YES]; 779fcddb20Sandy} 789fcddb20Sandy 799fcddb20Sandy@end 80