Migrate custom standalone samples and app clip to UIScene lifecycle

sample-app-first-batch
louisehsu 1 week ago
parent 28376d7c53
commit c8a96302f0

@ -1,18 +1,20 @@
import UIKit
import Flutter
import GoogleMaps
import UIKit
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
// TODO: Add your Google Maps API key
GMSServices.provideAPIKey("YOUR-API-KEY")
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
}
}

@ -24,6 +24,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>

@ -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>NSAppClip</key>
<dict>
<key>NSAppClipRequestEphemeralUserNotification</key>

@ -1,13 +1,16 @@
import UIKit
import Flutter
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate {
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
}
}

@ -24,6 +24,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>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>

@ -2,21 +2,33 @@
// 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 {
@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let flutterViewController = window.rootViewController as! FlutterViewController
FlutterMethodChannel(name: "methodChannelDemo", binaryMessenger: flutterViewController.binaryMessenger).setMethodCallHandler({
(call: FlutterMethodCall, result: FlutterResult) -> Void in
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
let messenger = engineBridge.applicationRegistrar.messenger()
FlutterMethodChannel(name: "methodChannelDemo", binaryMessenger: messenger)
.setMethodCallHandler({ (call: FlutterMethodCall, result: FlutterResult) -> Void in
guard let count = (call.arguments as? NSDictionary)?["count"] as? Int else {
result(FlutterError(code: "INVALID_ARGUMENT", message: "Value of count cannot be null", details: nil))
result(
FlutterError(
code: "INVALID_ARGUMENT",
message: "Value of count cannot be null",
details: nil
)
)
return
}
@ -30,10 +42,12 @@ import Flutter
}
})
FlutterBasicMessageChannel(name: "platformImageDemo", binaryMessenger: flutterViewController.binaryMessenger, codec: FlutterStandardMessageCodec.sharedInstance()).setMessageHandler{
(message: Any?, reply: FlutterReply) -> Void in
if(message as! String == "getImage") {
FlutterBasicMessageChannel(
name: "platformImageDemo",
binaryMessenger: messenger,
codec: FlutterStandardMessageCodec.sharedInstance()
).setMessageHandler { (message: Any?, reply: FlutterReply) -> Void in
if message as! String == "getImage" {
guard let image = UIImage(named: "eat_new_orleans.jpg") else {
reply(nil)
return
@ -43,30 +57,42 @@ import Flutter
}
}
FlutterEventChannel(name: "eventChannelDemo", binaryMessenger: flutterViewController.binaryMessenger).setStreamHandler(AccelerometerStreamHandler())
FlutterEventChannel(
name: "eventChannelDemo",
binaryMessenger: messenger
).setStreamHandler(AccelerometerStreamHandler())
var petList: [[String: String]] = []
// A FlutterBasicMessageChannel for sending petList to Dart.
let stringCodecChannel = FlutterBasicMessageChannel(name: "stringCodecDemo", binaryMessenger: flutterViewController.binaryMessenger, codec: FlutterStringCodec.sharedInstance())
let stringCodecChannel = FlutterBasicMessageChannel(
name: "stringCodecDemo",
binaryMessenger: messenger,
codec: FlutterStringCodec.sharedInstance()
)
// Registers a MessageHandler for FlutterBasicMessageChannel to receive pet details.
FlutterBasicMessageChannel(name: "jsonMessageCodecDemo", binaryMessenger: flutterViewController.binaryMessenger, codec: FlutterJSONMessageCodec.sharedInstance())
.setMessageHandler{(message: Any?, reply: FlutterReply) -> Void in
FlutterBasicMessageChannel(
name: "jsonMessageCodecDemo",
binaryMessenger: messenger,
codec: FlutterJSONMessageCodec.sharedInstance()
).setMessageHandler { (message: Any?, reply: FlutterReply) -> Void in
petList.insert(message! as! [String: String], at: 0)
stringCodecChannel.sendMessage(self.convertPetListToJson(petList: petList))
}
// Registers a MessageHandler for FlutterBasicMessageHandler to receive indices of detail records to remove from the petList.
FlutterBasicMessageChannel(name: "binaryCodecDemo", binaryMessenger: flutterViewController.binaryMessenger, codec: FlutterBinaryCodec.sharedInstance()).setMessageHandler{
(message: Any?, reply: FlutterReply) -> Void in
guard let index = Int.init(String.init(data: message! as! Data, encoding: String.Encoding.utf8)!) else {
FlutterBasicMessageChannel(
name: "binaryCodecDemo",
binaryMessenger: messenger,
codec: FlutterBinaryCodec.sharedInstance()
).setMessageHandler { (message: Any?, reply: FlutterReply) -> Void in
guard let index = Int(String(data: message! as! Data, encoding: String.Encoding.utf8)!) else {
reply(nil)
return
}
if (index >= 0 && index < petList.count) {
if index >= 0 && index < petList.count {
petList.remove(at: index)
reply("Removed Successfully".data(using: .utf8)!)
stringCodecChannel.sendMessage(self.convertPetListToJson(petList: petList))
@ -74,9 +100,6 @@ import Flutter
reply(nil)
}
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
// Function to convert petList to json string.

@ -24,6 +24,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>

@ -2,24 +2,33 @@
// 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)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
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({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
if ("switchView" == call.method) {
[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)
@ -28,13 +37,18 @@ import Flutter
let navigationController = UINavigationController(rootViewController: platformViewController)
navigationController.navigationBar.topItem?.title = "Platform View"
controller.present(navigationController, animated: true, completion: nil)
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)
}
});
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
})
}
func didUpdateCounter(counter: Int) {

@ -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>

Loading…
Cancel
Save