Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/content/platform-integration/platform-channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,16 @@ Override the `application:didFinishLaunchingWithOptions:` function and create
a `FlutterMethodChannel` tied to the channel name
`samples.flutter.dev/battery`:

:::note
If your app adopts the `UISceneDelegate` lifecycle,
`window` will be `nil` during `application(_:didFinishLaunchingWithOptions:)`.
To avoid a crash, instantiate your `FlutterMethodChannel`
and set its call handler within your `SceneDelegate`'s
`scene(_:willConnectTo:options:)` method,
accessing the controller by using
`window?.rootViewController as? FlutterViewController`.
:::

```swift title="AppDelegate.swift"
@main
@objc class AppDelegate: FlutterAppDelegate {
Expand Down Expand Up @@ -695,6 +705,16 @@ didFinishLaunchingWithOptions:` method.
Make sure to use the same channel name
as was used on the Flutter client side.

:::note
If your app adopts the `UISceneDelegate` lifecycle,
`window` will be `nil` during `application:didFinishLaunchingWithOptions:`.
To avoid a crash, instantiate your `FlutterMethodChannel`
and set its call handler within your `SceneDelegate`'s
`scene:willConnectToSession:options:` method,
accessing the controller by using
`(FlutterViewController*)self.window.rootViewController`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is correct or not, I'll need to defer to @jmagman on this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @LouiseHsu messaged @sfshaza2 with some code samples.

:::

```objc title="AppDelegate.m"
#import <Flutter/Flutter.h>
#import "GeneratedPluginRegistrant.h"
Expand Down
Loading