Skip to content
Merged
Changes from 2 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`.
Comment thread
sfshaza2 marked this conversation as resolved.
Outdated
:::

```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`.
Comment thread
sfshaza2 marked this conversation as resolved.
Outdated
:::

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