ios - 如何在 SceneDelegate 中有一个 flutter 方法处理程序?

标签 ios swift flutter

我有一个 music flutter 应用程序,现在我正在快速实现 native 播放器代码,该应用程序与 spotify ios sdk 集成。

我正在尝试运行,但 Spotify 连接功能在 IOS 13.6 手机上不起作用,我看到 IOS 13+ 更高版本需要 SceneDelegate。

现在我卡在了如何在 SceneDelegate 中添加 Flutter 方法处理程序上。

当我在 SceneDelegate 上添加 Flutter 方法处理程序时,出现以下错误,它将卡在断点处,接下来不会执行。

我正在尝试按照 AVFoundation 文档制作一个简单的视频取景器。该应用程序每次启动时都会终止。我该如何解决这个特定错误?

Thread 1: EXC_BREAKPOINT (code=1, subcode=0x102d3c320)

最佳答案

以下步骤帮助我将 Flutter 应用程序与 SceneDelegate 结合使用

  1. 创建 SceneDelegate.swift 包含子类 UIResponder 并符合 UIWindowSceneDelegate
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    
    var window: UIWindow?
    //....

}
  1. SceneManifest 添加到 Info.plist 中,我们在其中将 SceneDelegate 声明为场景的默认配置
<key>UIApplicationSceneManifest</key>
    <dict>
        <key>UIApplicationSupportsMultipleScenes</key>
        <true/>
        <key>UISceneConfigurations</key>
        <dict>
            <key>UIWindowSceneSessionRoleApplication</key>
            <array>
                <dict>
                    <key>UISceneConfigurationName</key>
                    <string>Default Configuration</string>
                    <key>UISceneDelegateClassName</key>
                    <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
                    <key>Storyboard Name</key>
                    <string>Main</string>
                </dict>
            </array>
        </dict>
    </dict>
  1. 更新 AppDelegate.swift 以支持 iOS 13 以外的其他版本
    override func application( _ application: UIApplication,
                               didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        guard #available(iOS 13.0, *) else {
            GeneratedPluginRegistrant.register(with: self)
            guard let controller = window?.rootViewController as? FlutterViewController else { return true }
            //Confugure 'controller' as needed
            return super.application(application, didFinishLaunchingWithOptions: launchOptions)
        }
        return true
    }
  1. 更新 SceneDelegate.swift 以支持 iOS 13+
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        guard let windowScene = scene as? UIWindowScene else { return }
        
        window = UIWindow(windowScene: windowScene)
        let flutterEngine = FlutterEngine(name: "SceneDelegateEngine")
        flutterEngine.run()
        GeneratedPluginRegistrant.register(with: flutterEngine)
        let controller = FlutterViewController.init(engine: flutterEngine, nibName: nil, bundle: nil)
        window?.rootViewController = controller
        window?.makeKeyAndVisible()
    }

关于ios - 如何在 SceneDelegate 中有一个 flutter 方法处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63631338/

相关文章:

flutter/Dart : Subclass a freezed data class

ios - RxSwift - 无法推断通用参数 'Self'

iOS 7 - 静默推送通知

android - Flex 移动项目选项

ios - 快速自定义 NSURLProtocol 错误

ios - 是否有任何公共(public) API 可以检测 iOS 16(beta 3)中的锁定模式?

ios - swift iOS : How to refactor a lot of conditions for if statement?

Flutter 等同于 React Native 的 onLayout?

ios - 警告 : under normal conditions, _fillInQueueWithExtraSpace:ignoreExistingItems: 不应重新输入

android - Flutter:无法使用 GradleScopeCompileServices.createGeneralCompileCaches() 创建 DefaultGeneralCompileCaches 类型的服务