mirror of
https://github.com/flutter/samples.git
synced 2026-10-10 03:11:13 +00:00
Migrate standard sample apps to UIScene lifecycle (#2884)
Fixes https://github.com/flutter/flutter/issues/176957
This commit is contained in:
@@ -2,42 +2,56 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import UIKit
|
||||
import Flutter
|
||||
import UIKit
|
||||
|
||||
@UIApplicationMain
|
||||
@objc class AppDelegate: FlutterAppDelegate, PlatformViewControllerDelegate {
|
||||
@main
|
||||
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate, PlatformViewControllerDelegate {
|
||||
var flutterResult: FlutterResult?
|
||||
|
||||
override func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
||||
) -> Bool {
|
||||
GeneratedPluginRegistrant.register(with: self)
|
||||
let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
|
||||
let channel = FlutterMethodChannel.init(name: "dev.flutter.sample/platform_view_swift", binaryMessenger: controller.binaryMessenger)
|
||||
|
||||
channel.setMethodCallHandler({
|
||||
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
|
||||
if ("switchView" == call.method) {
|
||||
self.flutterResult = result
|
||||
|
||||
let platformViewController = PlatformViewController(nibName: "PlatformViewController", bundle: nil)
|
||||
platformViewController.counter = call.arguments as! Int
|
||||
platformViewController.delegate = self
|
||||
|
||||
let navigationController = UINavigationController(rootViewController: platformViewController)
|
||||
navigationController.navigationBar.topItem?.title = "Platform View"
|
||||
controller.present(navigationController, animated: true, completion: nil)
|
||||
} else {
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
});
|
||||
|
||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||
}
|
||||
|
||||
func didUpdateCounter(counter: Int) {
|
||||
flutterResult?(counter)
|
||||
}
|
||||
|
||||
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
|
||||
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
|
||||
|
||||
let registrar = engineBridge.pluginRegistry.registrar(forPlugin: "PlatformViewSwift")
|
||||
let channel = FlutterMethodChannel(
|
||||
name: "dev.flutter.sample/platform_view_swift",
|
||||
binaryMessenger: engineBridge.applicationRegistrar.messenger()
|
||||
)
|
||||
|
||||
channel.setMethodCallHandler({
|
||||
[weak self] (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
|
||||
guard let self = self else { return }
|
||||
if "switchView" == call.method {
|
||||
self.flutterResult = result
|
||||
|
||||
let platformViewController = PlatformViewController(nibName: "PlatformViewController", bundle: nil)
|
||||
platformViewController.counter = call.arguments as! Int
|
||||
platformViewController.delegate = self
|
||||
|
||||
let navigationController = UINavigationController(rootViewController: platformViewController)
|
||||
navigationController.navigationBar.topItem?.title = "Platform View"
|
||||
|
||||
let presenter = registrar?.viewController ?? UIApplication.shared.connectedScenes
|
||||
.compactMap { $0 as? UIWindowScene }
|
||||
.flatMap { $0.windows }
|
||||
.first { $0.isKeyWindow }?
|
||||
.rootViewController
|
||||
|
||||
presenter?.present(navigationController, animated: true, completion: nil)
|
||||
} else {
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func didUpdateCounter(counter: Int) {
|
||||
flutterResult?(counter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,27 @@
|
||||
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UIApplicationSceneManifest</key>
|
||||
<dict>
|
||||
<key>UIApplicationSupportsMultipleScenes</key>
|
||||
<false/>
|
||||
<key>UISceneConfigurations</key>
|
||||
<dict>
|
||||
<key>UIWindowSceneSessionRoleApplication</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>UISceneClassName</key>
|
||||
<string>UIWindowScene</string>
|
||||
<key>UISceneConfigurationName</key>
|
||||
<string>flutter</string>
|
||||
<key>UISceneDelegateClassName</key>
|
||||
<string>FlutterSceneDelegate</string>
|
||||
<key>UISceneStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
@@ -41,5 +62,9 @@
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||
<true/>
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
Reference in New Issue
Block a user