-
Notifications
You must be signed in to change notification settings - Fork 6
/
TLAppDelegate.m
56 lines (48 loc) · 2.47 KB
/
TLAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#import "TLAppDelegate.h"
#import "TLRootViewController.h"
@implementation TLAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (@available(iOS 13.0, *)) {
return YES;
}
_window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
_myViewController = [[TLRootViewController alloc] init];
if (launchOptions[UIApplicationLaunchOptionsShortcutItemKey])
_myViewController.shortcutAction = launchOptions[UIApplicationLaunchOptionsShortcutItemKey];
_rootViewController = [[UINavigationController alloc] initWithRootViewController:_myViewController];
_rootViewController.navigationBarHidden = YES;
_window.rootViewController = _rootViewController;
[_window makeKeyAndVisible];
return YES;
}
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)) {
return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {
[_myViewController handleShortcutAction:shortcutItem.type withParameters:nil];
}
- (void)appWillEnterForeground:(UIApplication *)application {
[application endBackgroundTask:UIBackgroundTaskInvalid];
}
- (void)appDidEnterBackground:(UIApplication *)application {
__block UIBackgroundTaskIdentifier task;
task = [application beginBackgroundTaskWithExpirationHandler:^ {
[application endBackgroundTask:task];
task = UIBackgroundTaskInvalid;
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KILL_TIMEOUT * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
exit(0);
});
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
if (!url) return NO;
if ([url.scheme isEqualToString:@"leds"]) {
NSString *action = url.host;
if (action) {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
[_myViewController handleShortcutAction:action withParameters:components.queryItems];
}
}
return YES;
}
@end