My iOS app uses a FlutterMethodChannel and I’m adopting the new UISceneDelegate strategy described here: https://docs.flutter.dev/release/breaking-changes/uiscenedelegate

I’m trying to initialize it in didInitializeImplicitFlutterEngine and I’m getting a crash on this line:

let controller : FlutterViewController = window?.rootViewController as! FlutterViewController

The web page says that this line can cause a crash in application:didFinishLaunchingWithOptions:, but I wasn’t expecting it in didInitializeImplicitFlutterEngine.

The web page also mentions using a Bespoke FlutterViewController, but based on what that page says, I don’t think it applies in my case.

I’m happy to provide any other information that is needed to troubleshoot my problem.

Carl Smith's user avatar

If someone else has the same incredible mental block that I did, here is the correct code for setting up a FlutterMethodChannel in didInitializeImplicitFlutterEngine:

// Create method channels with `engineBridge.applicationRegistrar.messenger()` let batteryChannel = FlutterMethodChannel( name: "samples.flutter.dev/battery", binaryMessenger: engineBridge.applicationRegistrar.messenger() )

It’s spelled out plain as day in Section 2; I just had to copy and paste their code and change the channel name to match mine.

Create method channels and platform views in didInitializeImplicitFlutterEngine, if applicable.

Carl Smith's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.