|
| 1 | +# Migrating a Mindbox Flutter SDK integration to UISceneDelegate |
| 2 | + |
| 3 | +Starting with Flutter 3.35 the iOS engine ships `FlutterSceneDelegate`, and |
| 4 | +since Flutter 3.41 `UISceneDelegate`-based lifecycle is the recommended path |
| 5 | +for new iOS Flutter apps. The official Flutter migration guide is the |
| 6 | +authoritative source for everything not Mindbox-specific: |
| 7 | + |
| 8 | +- [Flutter UISceneDelegate migration guide][flutter-uiscene] |
| 9 | + |
| 10 | +This document only describes the Mindbox-side glue you need on top of the |
| 11 | +Flutter migration: where to forward `.launchScene` and `.universalLink` |
| 12 | +events, and what stays in your `AppDelegate`. It does **not** repeat the |
| 13 | +Flutter-side steps already covered in the link above (`Info.plist` scene |
| 14 | +manifest, `FlutterImplicitEngineDelegate` boilerplate, etc.) — follow them |
| 15 | +there and use this page for the Mindbox-specific bits. |
| 16 | + |
| 17 | +If your `Info.plist` does **not** contain `UIApplicationSceneManifest`, |
| 18 | +nothing changes for you. The Mindbox iOS SDK pod itself does not depend on |
| 19 | +any scene-specific Flutter API, so it keeps building and running on every |
| 20 | +Flutter version we supported before. You can update to the latest Mindbox |
| 21 | +SDK without touching your code. |
| 22 | + |
| 23 | +## Why this matters for Mindbox integrators |
| 24 | + |
| 25 | +Under `UIApplicationSceneManifest` two `AppDelegate` callbacks Mindbox |
| 26 | +previously relied on stop working as before: |
| 27 | + |
| 28 | +- `application(_:didFinishLaunchingWithOptions:)` still fires, but |
| 29 | + `launchOptions` is `nil`, so `Mindbox.shared.track(.launch(launchOptions))` |
| 30 | + tracks nothing useful. |
| 31 | +- `application(_:continue:restorationHandler:)` is never invoked — universal |
| 32 | + links arrive in `scene(_:continue:)` instead. |
| 33 | + |
| 34 | +To keep Mindbox receiving launch and universal-link events you need to |
| 35 | +forward them from your scene delegate. |
| 36 | + |
| 37 | +## Prerequisites |
| 38 | + |
| 39 | +- **Flutter ≥ 3.41** — required for `FlutterImplicitEngineDelegate` on the |
| 40 | + app side (see the Flutter guide above). |
| 41 | +- iOS deployment target ≥ 13.0. |
| 42 | + |
| 43 | +## What to add in your scene delegate |
| 44 | + |
| 45 | +Copy |
| 46 | +[`example/flutter_example/ios/Runner/SceneDelegate.swift`](../example/flutter_example/ios/Runner/SceneDelegate.swift) |
| 47 | +into your `Runner` target. The two relevant calls: |
| 48 | + |
| 49 | +```swift |
| 50 | +override func scene( |
| 51 | + _ scene: UIScene, |
| 52 | + willConnectTo session: UISceneSession, |
| 53 | + options connectionOptions: UIScene.ConnectionOptions |
| 54 | +) { |
| 55 | + Mindbox.shared.track(.launchScene(connectionOptions)) |
| 56 | + super.scene(scene, willConnectTo: session, options: connectionOptions) |
| 57 | +} |
| 58 | + |
| 59 | +override func scene( |
| 60 | + _ scene: UIScene, |
| 61 | + continue userActivity: NSUserActivity |
| 62 | +) { |
| 63 | + Mindbox.shared.track(.universalLink(userActivity)) |
| 64 | + super.scene(scene, continue: userActivity) |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +That replaces, respectively, `Mindbox.shared.track(.launch(launchOptions))` |
| 69 | +in `application(_:didFinishLaunchingWithOptions:)` and |
| 70 | +`Mindbox.shared.track(.universalLink(userActivity))` in |
| 71 | +`application(_:continue:restorationHandler:)`. |
| 72 | + |
| 73 | +You may keep both AppDelegate-side and SceneDelegate-side calls — in scene |
| 74 | +mode the AppDelegate-side `.launch(nil)` and `application(_:continue:)` are |
| 75 | +inert (`launchOptions == nil`, the method is not invoked), so the two paths |
| 76 | +do not produce duplicate events. |
| 77 | + |
| 78 | +## What stays unchanged in your AppDelegate |
| 79 | + |
| 80 | +Even after the scene migration you keep all of the following on your |
| 81 | +`AppDelegate` (typically a subclass of `MindboxFlutterAppDelegate`): |
| 82 | + |
| 83 | +- `Mindbox.shared.apnsTokenUpdate(deviceToken:)` in |
| 84 | + `application(_:didRegisterForRemoteNotificationsWithDeviceToken:)`. |
| 85 | +- `Mindbox.shared.pushClicked(response:)` and |
| 86 | + `Mindbox.shared.track(.push(response))` in your |
| 87 | + `UNUserNotificationCenterDelegate` methods. |
| 88 | +- `Mindbox.shared.registerBGTasks()`. |
| 89 | +- Notification permission requests. |
| 90 | + |
| 91 | +`UNUserNotificationCenterDelegate` is a process-global API and is not |
| 92 | +affected by scene mode, so push handling needs no changes. |
| 93 | + |
| 94 | +`MindboxFlutterAppDelegate` itself is scene-safe — it does not touch |
| 95 | +`window` or `rootViewController` — and continues to work as a base class |
| 96 | +unchanged. |
| 97 | + |
| 98 | +## Notification Service / Content Extensions |
| 99 | + |
| 100 | +`MindboxNotificationServiceExtension` and |
| 101 | +`MindboxNotificationContentExtension` are extension processes and have |
| 102 | +nothing to do with the host app's scene flow. They need no changes. |
| 103 | + |
| 104 | +## Reference implementation |
| 105 | + |
| 106 | +[`example/flutter_example/ios/Runner`](../example/flutter_example/ios/Runner) |
| 107 | +is fully migrated and serves as a working reference for both the |
| 108 | +Flutter-side and Mindbox-side parts of the migration. |
| 109 | + |
| 110 | +[flutter-uiscene]: https://docs.flutter.dev/release/breaking-changes/uiscenedelegate |
0 commit comments