Skip to content
Open
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions sites/docs/src/content/add-to-app/ios/add-flutter-screen.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ class AppDelegate: FlutterAppDelegate { // More on the FlutterAppDelegate.
GeneratedPluginRegistrant.register(with: self.flutterEngine);
return super.application(application, didFinishLaunchingWithOptions: launchOptions);
}

override func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions
) -> UISceneConfiguration {
let configuration = UISceneConfiguration(
name: nil,
sessionRole: connectingSceneSession.role
)
configuration.delegateClass = FlutterSceneDelegate.self
return configuration
}
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.

Hmm, I'm not sure where this is from, but I don't think this is what we want to recommend.

Add-to-App users need to update their SceneDelegate (or create one and add to Info.plist if they don't already have one) to subclass the FlutterSceneDelegate and if they can't, then to use the FlutterSceneLifeCycleProvider

See UIScene docs:
https://docs.flutter.dev/release/breaking-changes/uiscenedelegate#migration-guide-for-adding-flutter-to-existing-app-add-to-app
https://docs.flutter.dev/release/breaking-changes/uiscenedelegate#migrate-info-plist
https://docs.flutter.dev/release/breaking-changes/uiscenedelegate#migrate-info-plist

}
```

Expand Down Expand Up @@ -137,6 +150,15 @@ exposed as a property, on app startup in the app delegate.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (UISceneConfiguration *)application:(UIApplication *)application
configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession
options:(UISceneConnectionOptions *)options {
UISceneConfiguration *configuration = [[UISceneConfiguration alloc] initWithName:nil
sessionRole:connectingSceneSession.role];
configuration.delegateClass = [FlutterSceneDelegate class];
return configuration;
}

@end
```

Expand Down Expand Up @@ -375,6 +397,11 @@ The `FlutterAppDelegate` performs functions such as:
* Keeping the Flutter connection open
in debug mode when the phone screen locks.

As of Flutter 3.41, `UIScene` support is the default for iOS apps.
Comment thread
vashworth marked this conversation as resolved.
When using `FlutterAppDelegate`, you should also ensure that your app
uses `FlutterSceneDelegate` (or a subclass) to receive scene lifecycle
events, such as [`scene(_:openURLContexts:)`][] and [`scene(_:continue:)`][].

### Creating a FlutterAppDelegate subclass
Creating a subclass of the `FlutterAppDelegate` in UIKit apps was shown
in the [Start a FlutterEngine and FlutterViewController section][].
Expand All @@ -399,6 +426,19 @@ class AppDelegate: FlutterAppDelegate {
GeneratedPluginRegistrant.register(with: self.flutterEngine);
return true;
}

override func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions
) -> UISceneConfiguration {
let configuration = UISceneConfiguration(
name: nil,
sessionRole: connectingSceneSession.role
)
configuration.delegateClass = FlutterSceneDelegate.self
return configuration
}
}

@main
Expand Down Expand Up @@ -841,6 +881,8 @@ For a working example, refer to this [sample project][].
[`runApp`]: {{site.api}}/flutter/widgets/runApp.html
[`runWithEntrypoint`]: {{site.api}}/ios-embedder/interface_flutter_engine.html#a019d6b3037eff6cfd584fb2eb8e9035e
[`SystemNavigator.pop()`]: {{site.api}}/flutter/services/SystemNavigator/pop.html
[`scene(_:openURLContexts:)`]: {{site.apple-dev}}/documentation/uikit/uiscenedelegate/scene(_:openurlcontexts:)
[`scene(_:continue:)`]: {{site.apple-dev}}/documentation/uikit/uiscenedelegate/scene(_:continue:)
[tree-shaken]: https://en.wikipedia.org/wiki/Tree_shaking
[`WidgetsApp`]: {{site.api}}/flutter/widgets/WidgetsApp-class.html
[`PlatformDispatcher.defaultRouteName`]: {{site.api}}/flutter/dart-ui/PlatformDispatcher/defaultRouteName.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Finally, register the platform view.
This can be done in an app or a plugin.

For app registration,
modify the App's `AppDelegate.swift`:
implement the `didInitializeImplicitFlutterEngine:` method in the App's `AppDelegate.swift`:
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.

medium

In the Swift section, it is more idiomatic to use Swift method naming conventions instead of the Objective-C selector style.

Suggested change
implement the `didInitializeImplicitFlutterEngine:` method in the App's `AppDelegate.swift`:
implement the `didInitializeImplicitFlutterEngine(_:)` method in the App's `AppDelegate.swift`:


```swift
import Flutter
Expand Down Expand Up @@ -286,13 +286,16 @@ Finally, register the platform view.
This can be done in an app or a plugin.

For app registration,
modify the App's `AppDelegate.m`:
implement the `didInitializeImplicitFlutterEngine:` method in the App's `AppDelegate.m`:

```objc
#import "AppDelegate.h"
#import "FLNativeView.h"
#import "GeneratedPluginRegistrant.h"

@interface AppDelegate () <FlutterImplicitEngineDelegate>
@end

@implementation AppDelegate

- (void)didInitializeImplicitFlutterEngine:(NSObject<FlutterImplicitEngineBridge>*)engineBridge {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ Add support for Swift in the standard template setup that uses Objective-C:
1. Open the file `AppDelegate.swift` located under **Runner > Runner**
in the Project navigator.

Override the `application:didFinishLaunchingWithOptions:` function and create
Implement the `didInitializeImplicitFlutterEngine:` method and create
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.

medium

In the Swift section, it is more idiomatic to use Swift method naming conventions instead of the Objective-C selector style.

Suggested change
Implement the `didInitializeImplicitFlutterEngine:` method and create
Implement the `didInitializeImplicitFlutterEngine(_:)` method and create

a `FlutterMethodChannel` tied to the channel name
`samples.flutter.dev/battery`:

Expand Down Expand Up @@ -696,8 +696,8 @@ Start by opening the iOS host portion of the Flutter app in Xcode:
1. Open the file `AppDelegate.m`, located under **Runner > Runner**
in the Project navigator.

Create a `FlutterMethodChannel` and add a handler inside the `application
didFinishLaunchingWithOptions:` method.
Create a `FlutterMethodChannel` and add a handler inside the
`didInitializeImplicitFlutterEngine:` method.
Make sure to use the same channel name
as was used on the Flutter client side.

Expand All @@ -712,6 +712,9 @@ create your `FlutterMethodChannel` in the `didInitializeImplicitFlutterEngine` m
#import <Flutter/Flutter.h>
#import "GeneratedPluginRegistrant.h"

@interface AppDelegate () <FlutterImplicitEngineDelegate>
@end
Comment on lines 712 to +716
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.

medium

The Objective-C snippet for AppDelegate.m is missing the import for AppDelegate.h. This will cause a compilation error as the compiler won't recognize the AppDelegate class when declaring the category.

Suggested change
#import <Flutter/Flutter.h>
#import "GeneratedPluginRegistrant.h"
@interface AppDelegate () <FlutterImplicitEngineDelegate>
@end
#import "AppDelegate.h"
#import <Flutter/Flutter.h>
#import "GeneratedPluginRegistrant.h"
@interface AppDelegate () <FlutterImplicitEngineDelegate>
@end


@implementation AppDelegate

- (void)didInitializeImplicitFlutterEngine:(NSObject<FlutterImplicitEngineBridge>*)engineBridge {
Expand Down
Loading