-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[quick_actions_ios] UIScene Migration #11047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
5f64c02
0d2444f
fd058e5
495e311
b823134
6eaa5a3
bab8b38
3df0547
1728c3b
4aa4cf8
ea3650e
62d1755
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,19 @@ | |
| // found in the LICENSE file. | ||
|
|
||
| import Flutter | ||
| import UIKit | ||
|
|
||
| public final class QuickActionsPlugin: NSObject, FlutterPlugin, IOSQuickActionsApi { | ||
| public final class QuickActionsPlugin: NSObject, FlutterPlugin, IOSQuickActionsApi, | ||
| FlutterSceneLifeCycleDelegate | ||
| { | ||
|
|
||
| public static func register(with registrar: FlutterPluginRegistrar) { | ||
| let messenger = registrar.messenger() | ||
| let flutterApi = IOSQuickActionsFlutterApi(binaryMessenger: messenger) | ||
| let instance = QuickActionsPlugin(flutterApi: flutterApi) | ||
| IOSQuickActionsApiSetup.setUp(binaryMessenger: messenger, api: instance) | ||
| registrar.addApplicationDelegate(instance) | ||
| registrar.addSceneDelegate(instance) | ||
| } | ||
|
|
||
| private let shortcutItemProvider: ShortcutItemProviding | ||
|
|
@@ -72,6 +76,44 @@ public final class QuickActionsPlugin: NSObject, FlutterPlugin, IOSQuickActionsA | |
| } | ||
| } | ||
|
|
||
| // MARK: - FlutterSceneLifeCycleDelegate | ||
|
|
||
| public func scene( | ||
| _ scene: UIScene, | ||
| willConnectTo session: UISceneSession, | ||
| options connectionOptions: UIScene.ConnectionOptions? | ||
| ) -> Bool { | ||
| // Handle the case where app is launched via a shortcut item in scene-based lifecycle. | ||
| if let shortcutItem = connectionOptions?.shortcutItem { | ||
|
||
| // Keep hold of the shortcut type and handle it in the | ||
| // `sceneDidBecomeActive:` method once the Dart MethodChannel | ||
| // is initialized. | ||
| launchingShortcutType = shortcutItem.type | ||
| // Return false to indicate we handled the quick action to ensure | ||
| // the `windowScene:performActionFor:` method is not called. | ||
| return false | ||
| } | ||
| return true | ||
okorohelijah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public func sceneDidBecomeActive(_ scene: UIScene) { | ||
| if let shortcutType = launchingShortcutType { | ||
| handleShortcut(shortcutType) | ||
| launchingShortcutType = nil | ||
| } | ||
| } | ||
|
|
||
| public func windowScene( | ||
| _ windowScene: UIWindowScene, | ||
| performActionFor shortcutItem: UIApplicationShortcutItem, | ||
| completionHandler: @escaping (Bool) -> Void | ||
| ) -> Bool { | ||
| handleShortcut(shortcutItem.type) | ||
okorohelijah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return true | ||
| } | ||
|
|
||
| // MARK: - Shortcut handling | ||
|
|
||
| func handleShortcut(_ shortcut: String) { | ||
| flutterApi.launchAction(action: shortcut) { _ in | ||
| // noop | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.