Skip to content

Incompatibility with FlutterAppDelegate and Apple's Silent Push (content-available:true) #155479

Open
@hokstuff

Description

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 for silent push.
    • In my attached sample app on Github, I've integrated with the push provider Braze and followed these instructions.
  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
  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:).
  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.
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:

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!

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: existing-appsIntegration with existing apps via the add-to-app flowengineflutter/engine repository. See also e: labels.platform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform teamworkaround availableThere is a workaround available to overcome the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions