Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/share_plus/share_plus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 4.5.0

- iOS: Remove usage of deprecated UIApplication.keyWindow in iOS 13+
- Add `shareXFiles` implementations
- Deprecate `shareFiles*` implementations
- Enable `shareXFiles` implementations on Web
Expand Down
35 changes: 32 additions & 3 deletions packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,22 @@
static NSString *const PLATFORM_CHANNEL = @"dev.fluttercommunity.plus/share";

static UIViewController *RootViewController() {
return [UIApplication sharedApplication].keyWindow.rootViewController;
if (@available(iOS 13, *)) { // UIApplication.keyWindow is deprecated
NSSet *scenes = [[UIApplication sharedApplication] connectedScenes];
for (UIScene *scene in scenes) {
if ([scene isKindOfClass:[UIWindowScene class]]) {
NSArray *windows = ((UIWindowScene *)scene).windows;
for (UIWindow *window in windows) {
if (window.isKeyWindow) {
return window.rootViewController;
}
}
}
}
return nil;
} else {
return [UIApplication sharedApplication].keyWindow.rootViewController;
}
}

static UIViewController *
Expand Down Expand Up @@ -259,8 +274,15 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
return;
}

UIViewController *rootViewController = RootViewController();
if (!rootViewController) {
result([FlutterError errorWithCode:@"error"
message:@"No root view controller found"
details:nil]);
return;
}
UIViewController *topViewController =
TopViewControllerForViewController(RootViewController());
TopViewControllerForViewController(rootViewController);

[self shareText:shareText
subject:shareSubject
Expand Down Expand Up @@ -293,8 +315,15 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
}
}

UIViewController *rootViewController = RootViewController();
if (!rootViewController) {
result([FlutterError errorWithCode:@"error"
message:@"No root view controller found"
details:nil]);
return;
}
UIViewController *topViewController =
TopViewControllerForViewController(RootViewController());
TopViewControllerForViewController(rootViewController);
[self shareFiles:paths
withMimeType:mimeTypes
withSubject:subject
Expand Down