-
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 6 commits
5f64c02
0d2444f
fd058e5
495e311
b823134
6eaa5a3
bab8b38
3df0547
1728c3b
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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this new logic? did we have similar logic in legacy app delegate methods?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not new but similar to legacy which uses
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to remove the legacy code? |
||
| // Keep hold of the shortcut type and handle it in the | ||
| // `sceneDidBecomeActive:` method once the Dart MethodChannel | ||
| // is initialized. | ||
| launchingShortcutType = shortcutItem.type | ||
| // Return true to indicate we handled the connection. | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| 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
|
||
| completionHandler(true) | ||
| 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.