ios - 如何在 SceneDelegate 中有一个颤振方法处理程序?
问题描述
我有一个音乐颤振应用程序,现在我正在快速实现本机播放器代码,该应用程序与 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 一起使用
- 创建
SceneDelegate.swift
包含子类UIResponder
并符合UIWindowSceneDelegate
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
//....
}
- 添加
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>
- 更新
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
}
- 更新
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()
}
推荐阅读
- discord - 我正在尝试使用我的不和谐机器人发出命令,用 2 个随机不同的答案(discord.js)来回答问题
- database - 如何将抓取的数据存储在多个 Postregsql 表中?
- testng - 如何使@AfterTest alwaysRun 但仅在同一组中?
- html - Outllok 为 HTML Table 的行添加了额外的空格
- asp.net - 想要访问动态创建的嵌套中继器中的控件
- azure - 天蓝色政策只允许创建特定标签
- r - 如何在 SAS 中按行或列索引选择特定数据值?
- symfony - 日期时间对象的 Symfony HiddenType
- python - 如何将文件夹添加到 Django?
- php - 连接三个表并分组