Repository: flutter
Issue: Incompatibility with `FlutterAppDelegate` and Apple's Silent Push (`content-available:true`)
Labels: platform-ios,engine,a: existing-apps,P2,workaround available,team-ios,triaged-ios

### Steps to reproduce

1. Create a new Flutter app via `flutter create` that by default creates a Flutter iOS sample app that subclasses `FlutterAppDelegate`
2. Follow instructions to integrate Push notifications into your app, including the [ability to push background updates](https://developer.apple.com/documentation/usernotifications/pushing-background-updates-to-your-app) for silent push.
    - In my attached sample app on Github, I've integrated with the push provider [Braze](https://www.braze.com/) and followed [these instructions](https://braze-inc.github.io/braze-swift-sdk/tutorials/braze/b1-standard-push-notifications).
3. Once fully integrated, run the iOS app _on a physical device_ and accept the Push authorization prompt
4. To verify that push is correctly integrated, send a visible push notification and verify it is received in either the background or foreground. Based on the state, it may trigger a different Apple API
    - This API will trigger while in the foreground: [`userNotification(_:willPresent:withCompletionHandler:)`](https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/usernotificationcenter(_:willpresent:withcompletionhandler:))
    - In the background, no API will trigger unless you have `content-available:true` or if you interact with the notification
    - If not using a Push provider, it is possible to [send a Push notification via command line](https://developer.apple.com/documentation/usernotifications/sending-push-notifications-using-command-line-tools) but it requires some setup
5. Now, prepare to test sending a silent push with `content-available:true`. Add a breakpoint or print statement in `application(_:didReceiveRemoteNotification:fetchCompletionHandler)` and `userNotification(_:willPresent:withCompletionHandler:)`.
    - This silent push should [wake your app and trigger `application(_:didReceiveRemoteNotification:fetchCompletionHandler)`](https://developer.apple.com/documentation/usernotifications/pushing-background-updates-to-your-app#Receive-background-notifications) regardless if it is in the background or foreground. (There are some nuances [where delivery isn't guaranteed](https://developer.apple.com/documentation/usernotifications/pushing-background-updates-to-your-app#:~:text=update%20its%20content.-,Important,-The%20system%20treats), but we aren't concerned about it here)
6. In either background and foreground state, send a silent push to your app.
7. None of your breakpoints or print statements will be triggered. The silent push does not wake your app nor is the notification received by the Flutter iOS app.

<details>
<summary>Sample Push notification payloads used</summary>
<br>

```
// Visible payload
{
  "ab" : {
    "att" : {
      "aof" : 0,
      "type" : null,
      "url" : ""
    },
    "c" : "dGVzdF90ZXN0X2RpPTY2ZWRlNTlmMjQ0MzU4ZjY3Zjk5OTYwMTFjZjFhODlm"
  },
  "aps" : {
    "alert" : {
      "body" : "Text, no image",
      "title" : "Simple content"
    },
    "interruption-level" : "active",
    "mutable-content" : 1,
    "sound" : ""
  }
}

// Silent Push payload
{
  "ab" : {
    "c" : "dGVzdF90ZXN0X2RpPTY2ZWRlN2RlZDQ1YzY3NmNjYjNlODM0NWE2ZmQ3ZDJm"
  },
  "anythingElse" : "hi",
  "aps" : {
    "content-available" : 1,
    "interruption-level" : "active"
  },
  "isVisible" : "false",
  "shouldBeSilentPush" : "Yes"
}
```

</details>

### Additional context:
In the Flutter framework source code, there is some complex custom logic being done in [`FlutterAppDelegate.mm`](https://api.flutter.dev/ios-embedder/_flutter_app_delegate_8mm_source.html) and [`FlutterPluginAppLifeCycleDelegate.mm`](https://api.flutter.dev/ios-embedder/_flutter_plugin_app_life_cycle_delegate_8mm_source.html) that handles processing push notifications. However, this is outside of Apple's typical practices and it is possible that it interferes downstream with standard iOS push integrations.

### Expected results

In a Flutter iOS app which subclasses `FlutterAppDelegate` (by default) that successfully integrates Push Notifications, receiving a silent notification (where `content-available:true` with no visible content) does wake the Flutter app and trigger the expected Apple APIs, as noted in [Apple's official docs](https://developer.apple.com/documentation/usernotifications/pushing-background-updates-to-your-app#Receive-background-notifications):
- [`application(_:didReceiveRemoteNotification:fetchCompletionHandler)`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application)
- [`userNotification(_:willPresent:withCompletionHandler:)`](https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/usernotificationcenter(_:willpresent:withcompletionhandler:)) (if in the foreground)

### Actual results

Upon sending a silent push to a Flutter iOS app which subclasses `FlutterAppDelegate`, the silent push is not processed by the Flutter app and none of the expected Apple APIs are triggered

### Code sample

<details open><summary>Sample project on Github</summary>

https://github.com/hokstuff/FlutterAppDelegate_silentPushSample

</details>


### Screenshots or Video

_No response_

### Logs

<details open><summary>Logs</summary>

```console
flutter run
Connected devices:
Braze iPhone 1️⃣2️⃣ (mobile)    • 00008101-000C39CA3A40001E            • ios            • iOS 18.0
22A3354
iPhone 15 (mobile)              • 5AD2D6E6-3C49-403B-86D7-BB642AE9B37B • ios            •
com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
macOS (desktop)                 • macos                                • darwin-arm64   • macOS 14.5
23F79 darwin-arm64
Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 14.5
23F79 darwin-arm64
Chrome (web)                    • chrome                               • web-javascript • Google Chrome
128.0.6613.138

No wireless devices were found.

[1]: Braze iPhone 1️⃣2️⃣ (00008101-000C39CA3A40001E)
[2]: iPhone 15 (5AD2D6E6-3C49-403B-86D7-BB642AE9B37B)
[3]: macOS (macos)
[4]: Mac Designed for iPad (mac-designed-for-ipad)
[5]: Chrome (chrome)
Please choose one (or "q" to quit): 1
Launching lib/main.dart on Braze iPhone 1️⃣2️⃣ in debug mode...
ios/Runner/AppDelegate.swift uses the deprecated @UIApplicationMain attribute, updating.
Automatically signing iOS for device deployment using specified development team in Xcode project:
5GLZKGNWQ3
Running pod install...                                           1,642ms
Running Xcode build...                                                  
 └─Compiling, linking and signing...                         5.7s
Xcode build done.                                           25.7s
You may be prompted to give access to control Xcode. Flutter uses Xcode to run your app. If access is not
allowed, you can change this through your Settings > Privacy & Security > Automation.
Installing and launching...                                        29.3s
Syncing files to device Braze iPhone 1️⃣2️⃣...                      34ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on Braze iPhone 1️⃣2️⃣ is available at: http://127.0.0.1:58927/oc87Tn3nhKI=/
The Flutter DevTools debugger and profiler on Braze iPhone 1️⃣2️⃣ is available at:
http://127.0.0.1:9100?uri=http://127.0.0.1:58927/oc87Tn3nhKI=/
Lost connection to device.
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.5 23F79 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.93.1)
[✓] Connected device (5 available)
[✓] Network resources

• No issues found!
```

</details>