| Flutter iOS Embedder |

FlutterSharedApplication.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterSharedApplication.h"
6
7 #include "flutter/fml/logging.h"
8 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
9
10 FLUTTER_ASSERT_ARC
11
12 NSString* const kRestorationStateAppModificationKey = @"mod-date";
13
14 @implementation FlutterSharedApplication
15
16 + (BOOL)isAppExtension {
17 NSDictionary* nsExtension = [NSBundle.mainBundle objectForInfoDictionaryKey:@"NSExtension"];
18 return [nsExtension isKindOfClass:[NSDictionary class]];
19 }
20
21 + (BOOL)isAvailable {
22 // If the bundle is an App Extension, the application is not available.
23 // Therefore access to `UIApplication.sharedApplication` is not allowed.
24 return !FlutterSharedApplication.isAppExtension;
25 }
26
27 + (UIApplication*)application {
28 if (FlutterSharedApplication.isAvailable) {
29 return FlutterSharedApplication.sharedApplication;
30 }
31 return nil;
32 }
33
34 + (UIApplication*)
35 sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Accesses unavailable sharedApplication.") {
36 return UIApplication.sharedApplication;
37 }
38
39 + (BOOL)hasSceneDelegate {
40 if (FlutterSharedApplication.isAvailable) {
41 for (UIScene* scene in FlutterSharedApplication.sharedApplication.connectedScenes) {
42 if (scene.delegate != nil) {
43 return YES;
44 }
45 }
46 }
47 return NO;
48 }
49
50 + (int64_t)lastAppModificationTime {
51 NSDate* fileDate;
52 NSError* error = nil;
53 [[[NSBundle mainBundle] executableURL] getResourceValue:&fileDate
54 forKey:NSURLContentModificationDateKey
55 error:&error];
56 NSAssert(error == nil, @"Cannot obtain modification date of main bundle: %@", error);
57 return [fileDate timeIntervalSince1970];
58 }
59
60 + (BOOL)isFlutterDeepLinkingEnabled {
61 // Developers may disable deep linking through their Info.plist if they are using a plugin that
62 // handles deeplinking instead.
63 NSNumber* isDeepLinkingEnabled =
64 [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"];
65 // if not set, return YES
66 return isDeepLinkingEnabled ? [isDeepLinkingEnabled boolValue] : YES;
67 }
68
69 @end
FlutterMacros.h
FlutterSharedApplication.h
kRestorationStateAppModificationKey
FLUTTER_ASSERT_ARC NSString *const kRestorationStateAppModificationKey
Definition: FlutterSharedApplication.mm:12
FlutterSharedApplication
Definition: FlutterSharedApplication.h:13
FlutterSharedApplication::application
UIApplication * application
Definition: FlutterSharedApplication.h:27
FlutterSharedApplication::hasSceneDelegate
BOOL hasSceneDelegate
Definition: FlutterSharedApplication.h:32
FlutterSharedApplication::lastAppModificationTime
int64_t lastAppModificationTime
Definition: FlutterSharedApplication.h:34
FlutterSharedApplication::isAppExtension
BOOL isAppExtension
Definition: FlutterSharedApplication.h:17
FlutterSharedApplication::isAvailable
BOOL isAvailable
Definition: FlutterSharedApplication.h:22
+[FlutterSharedApplication isFlutterDeepLinkingEnabled]
BOOL isFlutterDeepLinkingEnabled()
Definition: FlutterSharedApplication.mm:60
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13