AppDelegate.swift 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import Flutter
  2. import UIKit
  3. @main
  4. @objc class AppDelegate: FlutterAppDelegate {
  5. override func application(
  6. _ application: UIApplication,
  7. didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  8. ) -> Bool {
  9. GeneratedPluginRegistrant.register(with: self)
  10. let controller = window?.rootViewController as! FlutterViewController
  11. FlutterMethodChannelManager.shared.setupMethodChannels(controller: controller)
  12. return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  13. }
  14. override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
  15. // 解析URL参数
  16. let components = URLComponents(url: url, resolvingAgainstBaseURL: true)
  17. let path = url.path
  18. // 将URL信息传递给Flutter
  19. let controller = window?.rootViewController as! FlutterViewController
  20. let channel = FlutterMethodChannel(name: "keyboard_ios", binaryMessenger: controller.binaryMessenger)
  21. if path == "/login" {
  22. channel.invokeMethod("navigateToLogin", arguments: nil)
  23. } else if path == "/member" {
  24. channel.invokeMethod("navigateToMember", arguments: nil)
  25. }
  26. return true
  27. }
  28. }