Skip to content

Commit b22f2d6

Browse files
committed
added comments
1 parent 513f58c commit b22f2d6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ios/Classes/OpenFilePlugin.m

+17
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,52 @@ @interface OpenFilePlugin ()<UIDocumentInteractionControllerDelegate>
55

66
static NSString *const CHANNEL_NAME = @"open_file";
77

8+
// Returns the root view controller of the app,
9+
// or nil if the app has no root view controller.
810
static UIViewController *RootViewController() {
11+
// If the app is running on iOS 13 or higher, then use the new `connectedScenes`
12+
// API to get the root view controller of the key window.
913
if (@available(iOS 13, *)) {
14+
// Get a list of all the connected scenes in the app.
1015
NSSet *scenes = [[UIApplication sharedApplication] connectedScenes];
16+
// Iterate over the scenes and check if each one is a UIWindowScene.
1117
for (UIScene *scene in scenes) {
1218
if ([scene isKindOfClass:[UIWindowScene class]]) {
19+
// Get a list of all the windows in the scene.
1320
NSArray *windows = ((UIWindowScene *)scene).windows;
21+
// Iterate over the windows and check if each one is the key window.
1422
for (UIWindow *window in windows) {
1523
if (window.isKeyWindow) {
24+
// Return the root view controller of the key window.
1625
return window.rootViewController;
1726
}
1827
}
1928
}
2029
}
30+
// If we couldn't find a key window, then return nil.
2131
return nil;
2232
} else {
33+
// Simply return the root view controller of the key window.
2334
return [UIApplication sharedApplication].keyWindow.rootViewController;
2435
}
2536
}
2637

38+
// Returns the top view controller in a view controller hierarchy.
2739
static UIViewController *
2840
TopViewControllerForViewController(UIViewController *viewController) {
41+
// If the view controller has a presented view controller, then return the top
42+
// view controller in that hierarchy.
2943
if (viewController.presentedViewController) {
3044
return TopViewControllerForViewController(
3145
viewController.presentedViewController);
3246
}
47+
// If the view controller is a navigation controller, then return the top
48+
// view controller in the navigation controller's stack.
3349
if ([viewController isKindOfClass:[UINavigationController class]]) {
3450
return TopViewControllerForViewController(
3551
((UINavigationController *)viewController).visibleViewController);
3652
}
53+
// Otherwise, return the given view controller.
3754
return viewController;
3855
}
3956

0 commit comments

Comments
 (0)