-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[firebase_messaging] Handle background messages on iOS #2016
Conversation
… ios-background-support
… ios-background-support
… ios-background-support
… ios-background-support
… ios-background-support
…n readme (and some restructuring in readme)
Really looking forward to this, thanks for your work! |
Thanks for your great work, only worked in background .when app killed not work? |
@shell32 what device are you testing on? If you force kill an app on iOS (common when testing things like this) then iOS will not deliver push notifications to that app until the app or device is restarted. |
iphone 6 , ios 12 |
@shell32, just as @athornz says the app is not receiving any push notifications if the app has been force-quit. If the app has been suspended by the system (which happens quite fast) the app should be woken up and get some time to process a notification. When I've been testing I've also noticed that it can take a couple of minutes sometimes before the app is woken up if it has been suspended. You can read a bit more here: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application#discussion |
Looking forward to this, thanks for your work! |
can this pr solve this issue? |
@p30arena No, it only deals with handling push messages when app is in background or suspended state for iOS. |
@campioncino this pull request is not adding that behaviour. It's just about adding background handling for push messages. So when your app is in the background you'll be able to provide a dart function/isolate that should handle the message. |
I'm sorry, I mean : can I finally do something like the image. Using |
@campioncino Ok :) I guess that should be possible. Anything should be possible in the backgroundMessageHandler. Like fetching data from backend or trigger local notifications. |
@isaiahtaylor, please don't post android config on a thread for iOS. There is no point here. |
I edited my comment to note that this is not necessarily relevant to this issue, it's just something that you might run into following this path. |
@fanatic75 have you tried the console app on iOS? If you lose the connection with the app in the IDE-console you should still be able to see the logs from the app in the stand alone console app. |
@
I have moved from data message to notification message which solves the background problem on IOS as well. OnLaunch is working once the app has been killed and onResume is working when the app is in background. Not using background message callback anymore on both platforms. |
| **Notification on Android** | `onMessage` | Notification is delivered to system tray. When the user clicks on it to open app `onResume` fires if `click_action: FLUTTER_NOTIFICATION_CLICK` is set (see below). | Notification is delivered to system tray. When the user clicks on it to open app `onLaunch` fires if `click_action: FLUTTER_NOTIFICATION_CLICK` is set (see below). | | ||
| **Notification on iOS** | `onMessage` | Notification is delivered to system tray. When the user clicks on it to open app `onResume` fires. | Notification is delivered to system tray. When the user clicks on it to open app `onLaunch` fires. | | ||
| **Data Message on Android** | `onMessage` | `onMessage` while app stays in the background. | *not supported by plugin, message is lost* | | ||
| **Data Message on iOS** | `onMessage` | Message is stored by FCM and delivered to app via `onMessage` when the app is brought back to foreground. | Message is stored by FCM and delivered to app via `onMessage` when the app is brought back to foreground. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right? Aren't background messages delivered through onBackgroundMessage
after this patch?
import firebase_messaging | ||
``` | ||
|
||
1. Then add the following code to `AppDelegate.swift`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you should specify where in AppDelegate.swift
? E.g. didFinishLaunchingWithOptions
if that is the case.
is it also possible to use the background message handling on an iOS Simulator? Or is this one of the things that only work on a proper iOS device? |
As far as I know this will only work on real devices. |
Only conflicts are changelog and pubspec? This is a critical merge for my app. |
# Conflicts: # packages/firebase_messaging/CHANGELOG.md # packages/firebase_messaging/pubspec.yaml Updated version in CHANGELOG.md and pubspec.yaml
Is this schedule for merge? We need this in our app. |
| **Notification on Android** | `onMessage` | Notification is delivered to system tray. When the user clicks on it to open app `onResume` fires if `click_action: FLUTTER_NOTIFICATION_CLICK` is set (see below). | Notification is delivered to system tray. When the user clicks on it to open app `onLaunch` fires if `click_action: FLUTTER_NOTIFICATION_CLICK` is set (see below). | | ||
| **Notification on iOS** | `onMessage` | Notification is delivered to system tray. When the user clicks on it to open app `onResume` fires. | Notification is delivered to system tray. When the user clicks on it to open app `onLaunch` fires. | | ||
| **Data Message on Android** | `onMessage` | `onMessage` while app stays in the background. | *not supported by plugin, message is lost* | | ||
| **Data Message on iOS** | `onMessage` | Message is delivered to `onBackgroundMessage`. This is the case both when app is running in background and the system has suspended the app. | Whan app is force-quit by the user the message is not handled. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Whan app is force-quit by the user the message is not handled.
You got a typo there. It should be called "When" :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed.
Hi @FirebaseExtended/invertase! Any chance you could take a look at this pull request? It's a really wanted feature for us and (as it seems) a lot of other people. |
Hi @Salakar! I tried to tag the @FirebaseExtended/invertase team as suggested here: FlutterFire Roadmap but don't seem to work. Any chance any of you could take a look at this pull request? |
Any updates on this? |
@collinjackson @Ehesp @kroikie @Salakar guys please review this one, we all need it 🙏🥺 |
Hold on to your hats... New dev release coming soon. |
# Conflicts: # packages/firebase_messaging/CHANGELOG.md # packages/firebase_messaging/pubspec.yaml
@ozcannn14 why would you JSON.stringify your |
I have used this PR and it works. One thing that bit me was that when testing with a local clone of the fork, it seems that firebase_messaging gets initialized before firebase_core and that is not handled very well in the An entirely different issue is that because of flutter/flutter#14815, I cannot do any of the processing I had in mind in the background isolate and thus it is effectively useless to me to have background support on iOS. |
Description
Enable backgound handling on iOS to work the same way as android.
Related Issues
See Issue 47
Related pull request
This pull request was inspired by this one: Pull request 53
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?