Incompatibility with FlutterAppDelegate
and Apple's Silent Push (content-available:true
) #155479
Description
Steps to reproduce
- Create a new Flutter app via
flutter create
that by default creates a Flutter iOS sample app that subclassesFlutterAppDelegate
- Follow instructions to integrate Push notifications into your app, including the ability to push background updates for silent push.
- In my attached sample app on Github, I've integrated with the push provider Braze and followed these instructions.
- Once fully integrated, run the iOS app on a physical device and accept the Push authorization prompt
- 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:)
- 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 but it requires some setup
- This API will trigger while in the foreground:
- Now, prepare to test sending a silent push with
content-available:true
. Add a breakpoint or print statement inapplication(_:didReceiveRemoteNotification:fetchCompletionHandler)
anduserNotification(_:willPresent:withCompletionHandler:)
.- This silent push should wake your app and trigger
application(_:didReceiveRemoteNotification:fetchCompletionHandler)
regardless if it is in the background or foreground. (There are some nuances where delivery isn't guaranteed, but we aren't concerned about it here)
- This silent push should wake your app and trigger
- In either background and foreground state, send a silent push to your app.
- 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.
Sample Push notification payloads used
// 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"
}
Additional context:
In the Flutter framework source code, there is some complex custom logic being done in FlutterAppDelegate.mm
and FlutterPluginAppLifeCycleDelegate.mm
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:
application(_:didReceiveRemoteNotification:fetchCompletionHandler)
userNotification(_: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
Sample project on Github
https://github.com/hokstuff/FlutterAppDelegate_silentPushSample
Screenshots or Video
No response
Logs
Logs
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.
Flutter Doctor output
Doctor output
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!