How to have a flutter method handler in SceneDelegate?

Viewed 815

I have a music flutter app and now i am implementing the native player code in swift the app is integrated with spotify ios sdk.

i am trying to run and the spotify connect function is not working on IOS 13.6 phone, i saw that IOS 13+ later versions need SceneDelegate.

Now i am stuck at how to add the Flutter method handler in SceneDelegate.

When i add the Flutter method handler on SceneDelegate i get the below error it will be stuck at a breakpoint wont execute next.

I'm trying to make a simple video viewfinder by following AVFoundation documentation. The app terminates every time it is launched. How do I resolve this particular error?

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

The following steps helped me use the Flutter application with SceneDelegate

  1. Create SceneDelegate.swift containing a subclass UIResponder and conforms to UIWindowSceneDelegate
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    
    var window: UIWindow?
    //....

}
  1. Add SceneManifest to Info.plist, in which we declare our SceneDelegate as being the default configuration for a scene
<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. Update AppDelegate.swift to support other versions than 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. Update SceneDelegate.swift to support 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()
    }
Related