firebase / flutterfire

šŸ”„ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.69k stars 3.97k forks source link

[firebase_messaging]: onBackgroundMessage() won't work after Reboot on iOS #12324

Closed Gobmichet closed 7 months ago

Gobmichet commented 8 months ago

Is there an existing issue for this?

Are you aware of the differences between iOS and Android background message handling?

Do you have an active Apple Developer account?

Are you using a physical iOS device to test background messages?

Have you enabled "Remote Notifications" & "Background Mode" (Checking options for "Background Processing" & "Remote Notifications") in your app's Xcode project?

BG modes

Have you created an APNs key in your Apple Developer account & uploaded this APNs key to your Firebase console?

APNKeys

Have you disabled method swizzling for Firebase in your app?

no such thing in our info.plist

Are you sending messages to your app from the Firebase Admin SDK?

Also tested with the project you recommend (flutterfire's nodeJS Firebase admin SDK script in previous section) : ObjetNotif

Otherwise, we use the Java firebase library :

<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>9.2.0</version>
</dependency>

like : Springboot_SendMsg

Have you requested permission from the user to receive notifications?

Have you used the 'Console' application on your macOS device to check if the iOS device's system is throttling your background messages?

MacConsole

Additional context and comments

Briefly :

BUT AFTER THE IPHONE's REBOOT :

and as we can see in the MacOs console stackTrace screenshot :

response : { Decision : Must Not Proceed , Score : 0.00 [...] }

What are we missing so that the BG part still works after the device's reboot on iOS !? Did i miss a configuration part or something ? a parameter maybe ? (We do use content-available : true and priority ones)

How to transform this "must not proceed" decision from iOS when receiving the notification (that, again, we do receive on the phone,) in "can proceed" or "must proceed" so that the background callback code works normally !?

Any help would be MUCH appreciated ! (^_^)

Thanks in advance.

darshankawar commented 8 months ago

@Gobmichet Can you try this and see if it helps in your case ? Also, can you provide the iOS device details you are using ?

Gobmichet commented 8 months ago

Hi,

After several additionnal tests & researches here's what we can add to the "diagnosis" :

We test the flutter app on iOS physical device via testFlight in order to be able to test the background/terminated/reboot states and here's what we observe :

Indeed :

But AFTER the device REBOOT, everything is broken and no notifications are bg handled anymore until another notification received in foreground !

So the problem really seems to be the starting of that background handler !

saying that we did add this code found on the firebase site when creating an app :

iOS_bg_2

And here is our code :

import UIKit
import Flutter
import FirebaseCore

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

But no changes, still doesn't work :(

Can someone please help us to get that BG handler part to work on iOS since it already works like a charm on Android ???

Help would REALLY be appreciated ! ;)

PS : last tests stackTrace from macOS when receiving a notification... "CANCELED" ? finalTrace

darshankawar commented 8 months ago

Thanks for the update. I am not sure what should be the expected behavior after rebooting the device, ideally, it should resume the actions as before, but wondering if in this case, the native ios comes into picture or not.

I'll keep the issue open and label for team's input.

Gobmichet commented 8 months ago

Thanks in advance, we're really stuck in here and think we do have already tried everything possible :(

russellwheatley commented 8 months ago

The system is blocking your notifications from appearing. This isn't a bug in firebase messaging. Try using data only messages. When you say reboot, do you mean switch iPhone off & on?

Gobmichet commented 7 months ago

yes i do ;)

Notifications ALWAYS do appear on the phone "Just" the background peristance isn't triggered and ONLY on iPhone.

indeed the only way to have the background code to work is to first receive a notification in foreground (app opened) then it works UNTIL you reboot the iPhone.

After reboot nothing works anymore until a first notif is again received when app is opened.

google-oss-bot commented 7 months ago

Hey @Gobmichet. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 7 months ago

Since there haven't been any recent updates here, I am going to close this issue.

@Gobmichet if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.