-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTLSceneDelegate.m
52 lines (45 loc) · 2.35 KB
/
TLSceneDelegate.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
#import "TLSceneDelegate.h"
@implementation TLSceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)) {
UIWindowScene *windowScene = (UIWindowScene *)scene;
_window = [[UIWindow alloc] initWithWindowScene:windowScene];
_myViewController = [[TLRootViewController alloc] init];
if (connectionOptions.shortcutItem)
_myViewController.shortcutAction = connectionOptions.shortcutItem.type;
_rootViewController = [[UINavigationController alloc] initWithRootViewController:_myViewController];
_rootViewController.navigationBarHidden = YES;
_window.rootViewController = _rootViewController;
[_window makeKeyAndVisible];
}
- (void)windowScene:(UIWindowScene *)windowScene performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler API_AVAILABLE(ios(13.0)) {
[_myViewController handleShortcutAction:shortcutItem.type withParameters:nil];
completionHandler(YES);
}
- (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
[[UIApplication sharedApplication] endBackgroundTask:UIBackgroundTaskInvalid];
}
- (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)) {
__block UIBackgroundTaskIdentifier task;
UIApplication *application = [UIApplication sharedApplication];
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);
});
}
- (void)scene:(UIScene *)scene openURLContexts:(NSSet <UIOpenURLContext *> *)URLContexts API_AVAILABLE(ios(13.0)) {
for (UIOpenURLContext *context in URLContexts) {
NSURL *url = context.URL;
if (!url) continue;
if ([url.scheme isEqualToString:@"leds"]) {
NSString *action = url.host;
if (action) {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
[_myViewController handleShortcutAction:action withParameters:components.queryItems];
}
}
}
}
@end