|
4 | 4 | @implementation TLAppDelegate |
5 | 5 |
|
6 | 6 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { |
7 | | - if (@available(iOS 13.0, *)) { |
8 | | - return YES; |
9 | | - } |
10 | | - _window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; |
11 | | - _myViewController = [[TLRootViewController alloc] init]; |
12 | | - if (launchOptions[UIApplicationLaunchOptionsShortcutItemKey]) |
13 | | - _myViewController.shortcutAction = launchOptions[UIApplicationLaunchOptionsShortcutItemKey]; |
14 | | - _rootViewController = [[UINavigationController alloc] initWithRootViewController:_myViewController]; |
15 | | - _rootViewController.navigationBarHidden = YES; |
16 | | - _window.rootViewController = _rootViewController; |
17 | | - [_window makeKeyAndVisible]; |
18 | | - return YES; |
| 7 | + if (@available(iOS 13.0, *)) { |
| 8 | + return YES; |
| 9 | + } |
| 10 | + _window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; |
| 11 | + _myViewController = [[TLRootViewController alloc] init]; |
| 12 | + if (launchOptions[UIApplicationLaunchOptionsShortcutItemKey]) |
| 13 | + _myViewController.shortcutAction = launchOptions[UIApplicationLaunchOptionsShortcutItemKey]; |
| 14 | + _rootViewController = [[UINavigationController alloc] initWithRootViewController:_myViewController]; |
| 15 | + _rootViewController.navigationBarHidden = YES; |
| 16 | + _window.rootViewController = _rootViewController; |
| 17 | + [_window makeKeyAndVisible]; |
| 18 | + return YES; |
19 | 19 | } |
20 | 20 |
|
21 | 21 | - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)) { |
22 | 22 | return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; |
23 | 23 | } |
24 | 24 |
|
25 | 25 | - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler { |
26 | | - [_myViewController handleShortcutAction:shortcutItem.type]; |
| 26 | + [_myViewController handleShortcutAction:shortcutItem.type]; |
27 | 27 | } |
28 | 28 |
|
29 | | -- (void)applicationWillResignActive:(UIApplication *)application { |
30 | | - [_myViewController releaseStream]; |
| 29 | +- (void)appWillEnterForeground:(UIApplication *)application { |
| 30 | + [application endBackgroundTask:UIBackgroundTaskInvalid]; |
31 | 31 | } |
32 | 32 |
|
33 | | -- (void)applicationDidBecomeActive:(UIApplication *)application { |
34 | | - [_myViewController setupStream]; |
| 33 | +- (void)appDidEnterBackground:(UIApplication *)application { |
| 34 | + __block UIBackgroundTaskIdentifier task; |
| 35 | + task = [application beginBackgroundTaskWithExpirationHandler:^ { |
| 36 | + [application endBackgroundTask:task]; |
| 37 | + task = UIBackgroundTaskInvalid; |
| 38 | + }]; |
| 39 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KILL_TIMEOUT * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ |
| 40 | + exit(0); |
| 41 | + }); |
35 | 42 | } |
36 | 43 |
|
37 | 44 | @end |
0 commit comments