Open vishnukvmd opened 3 years ago
@vishnukvmd How are you terminating the app ? Is it by swiping away from recent screens ? If so, in that case we need to manually re-open the app again for messages to start working. Can you try the same and see if this aspect helps ?
Hey @darshankawar , I've already made sure that the app is never manually terminated.
@vishnukvmd Thanks for the update. Is there a simpler way to replicate this issue to analyze where the issue could be along with a sample data only payload ?
@darshankawar Since a server/script is required to send out an intermittent push, an example that includes the service would be non-trivial.
This is reproducible behavior for all pushes with a data-only message that looks like this:
message := &messaging.MulticastMessage{
Tokens: tokens,
Data: map[string]string{"action": "sync"},
APNS: &messaging.APNSConfig{
Headers: map[string]string{
"apns-push-type": "background",
"apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
"apns-topic": "io.ente.frame", // bundle identifier
},
Payload: &messaging.APNSPayload{Aps: &messaging.Aps{ContentAvailable: true}},
},
}
The message results in an app startup 100% of the times, so there are no delivery issues.
The problem here is that there's no way to identify if the app was started in the foreground, or if it was started as a result of a background push.
Keeping it open for further insights from the team on correct / expected behavior in this case.
Any update on this issue? We are also facing this issue. The main flutter application starts running in the background and it is causing the side-effects.
The expected behaviour should be to execute only the high level function mentioned in FirebaseMessaging.onBackgroundMessage
.
We noticed that on background application launch, the execution gets stopped if any Screen navigation code is present like Navigator.pushReplacementNamed(context, AppRoutes.loginScreen)
So one workaround we found was to launch the application in dummy screen and automatically shift to FirstScreen/HomeScreen after 0.1 seconds of delay. We need to remove the screen navigation animation in this case. Now if user opens the application it is working, user would not notice the dummy screen and when application is launched in background because of data-only notification, the main app execution is stopped but the high level function is still working. In our case the high level function is inside a separate isolate.
Hi, do we have any update on this issue?
Not sure if this is relevant. In the react-native plugin, it mentions that the app would get mounted from the background handler. There is some headless check.
https://rnfirebase.io/messaging/usage#background-application-state
@darshankawar Any update on this issue?
@raphire08 Can you please share a few details on how did you solve the main method execution? Your help will be much appreciated, thanks.
@Lyokone Were you able to test it?
Actually it is reproducible in the example app as well.
onBackgroundMessage
callback. main
method. main
method gets called. We are having quite a difficult time due to this bug. Hey @adar2378 It seems related to how Flutter is handling waking up the dart Isolate. It keeps firing up the main even thought this is just handling the background notification. Not sure if it can be solved from the FlutterFire side for now.
@Lyokone Is there any way to detect if the it was triggered(calling main method) by background isolate, or a normal user is opening the app? Or any issues on Flutter GH that you know is tracking this issue?
This bug holds back the feature to show user action when app is terminated as the onBackgroundMessage
callback is not called?
@adar2378 We implemented something like this
void main() {
// fireabase initialization
// firebase messaging on background call
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const DummyScreen(),
);
}
}
class DummyScreen extends StatefulWidget {
const DummyScreen({super.key});
@override
State<DummyScreen> createState() => _DummyScreenState();
}
class _DummyScreenState extends State<DummyScreen> with WidgetsBindingObserver {
bool isLaunched = false;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
if (WidgetsBinding.instance.lifecycleState != null) {
if (WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed) {
openHomeScreen();
}
}
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.resumed) {
openHomeScreen();
}
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
Future<void> openHomeScreen() async {
if (!isLaunched) {
isLaunched = true;
await Future.delayed(const Duration(milliseconds: 100));
if (mounted) {
// navigator push
}
}
}
@override
Widget build(BuildContext context) {
return Container();
}
}
This bug holds back the feature to show user action when app is terminated as the
onBackgroundMessage
callback is not called?
True, it is a problem to handle user action in terminated state for iOS
@adar2378 We implemented something like this
void main() { // fireabase initialization // firebase messaging on background call runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const DummyScreen(), ); } } class DummyScreen extends StatefulWidget { const DummyScreen({super.key}); @override State<DummyScreen> createState() => _DummyScreenState(); } class _DummyScreenState extends State<DummyScreen> with WidgetsBindingObserver { bool isLaunched = false; @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); if (WidgetsBinding.instance.lifecycleState != null) { if (WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed) { openHomeScreen(); } } } @override void didChangeAppLifecycleState(AppLifecycleState state) { super.didChangeAppLifecycleState(state); if (state == AppLifecycleState.resumed) { openHomeScreen(); } } @override void dispose() { super.dispose(); WidgetsBinding.instance.removeObserver(this); } Future<void> openHomeScreen() async { if (!isLaunched) { isLaunched = true; await Future.delayed(const Duration(milliseconds: 100)); if (mounted) { // navigator push } } } @override Widget build(BuildContext context) { return Container(); } }
Thanks, will check
is there any solution ??
Oh my God, it's been 2 years and it's still not resolved?
Oh my God, it's been 2 years and it's still not resolved?
Unfortunately yes π₯
Many years have passed. Please tell me why it is not being fixed... Is it a bug that can't be fixed? We are planning a new program in the future. We need to know when this bug will be fixed so that we can plan. Can you tell us some future plans or timelines for this bug?
did any one find a way to check whether the app open from background or normal open ?
did any one find a way to check whether the app open from background or normal open ?
please check
did any one find a way to check whether the app open from background or normal open ?
please check #6517
thanks for your reply , but its the same issue as this, but not answering my question ... i found : https://github.com/firebase/flutterfire/issues/7407#issuecomment-1470016838 can help to turn around the issue , its not solve the issue , but can help at least to avoid any heavy work on the main isolate when call come from termination , i test it now and its works
did any one find a way to check whether the app open from background or normal open ?
please check #6517
thanks for your reply , but its the same issue as this, but not answering my question ... i found : #7407 (comment) can help to turn around the issue , its not solve the issue , but can help at least to avoid any heavy work on the main isolate when call come from termination , i test it now and its works
I'll check it out thank you
I think the firebase team should collaborate with Flutter team resolve this. It's one of the core features I think when it comes to messaging app and replying from notifications directly etc.
Hello, any updates on this issue? the AppLifecycleState.resumed
workaround does the trick but still, would be nice to see this fixed.
This issue still occurs in firebase_messaging: ^14.6.8. Any update for this issue?
This issue still occurs in firebase_messaging: ^14.6.8. Any update for this issue?
@vishnukvmd How are you terminating the app ? Is it by swiping away from recent screens ? If so, in that case we need to manually re-open the app again for messages to start working. Can you try the same and see if this aspect helps ? hello @darshankawar , where do you find this information? I am debugging exactly this issue and looking for some reference about it. Could you please give me some reference about this behaviour? Thank you
Bug report
Describe the bug
On iOS, registering a top-level function with
FirebaseMessaging.onBackgroundMessage
does not guarantee that it will get invoked when a data-only push (without a notification payload) is received when the app is dead.Instead, the top-level
main
function is called without theRemoteMessage
object.Steps to reproduce
Steps to reproduce the behavior:
BackgroundMessageHandler
withFirebaseMessaaging.onBackgroundMessage
that simply logs the incomingRemoteMessage
to a file.ContentAvailable
push to this device.main
that logs it's invocation to the same file.BackgroundMessageHandler
is never called when the app is dead.After 24 hours if you check the log file, you will observe that as long as the app is alive the
BackgroundMessageHandler
will be called, and otherwise themain
function will be called.Expected behavior
BackgroundMessageHandler
should always be called.Additional context
On iOS, it is important to not do heavy operations when the app is in the background. Since the
main
function is now being invoked on background pushes, there is no way for application developers to understand if the app was started by the user or by a background push. If there is some other way to determine this, please let me know, we would be grateful.Flutter doctor
Run
flutter doctor
and paste the output below:Click To Expand
``` $ flutter doctor [β] Flutter (Channel stable, 2.5.2, on macOS 11.3.1 20E241 darwin-arm, locale en-IN) [β] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [β] Xcode - develop for iOS and macOS [β] Chrome - develop for the web [!] Android Studio (not installed) [β] IntelliJ IDEA Ultimate Edition (version 2021.2) [β] VS Code (version 1.62.2) [β] Connected device (3 available) ! Doctor found issues in 1 category. ```Flutter dependencies
Run
flutter pub deps -- --style=compact
and paste the output below:Click To Expand
``` β flutter pub deps -- --style=compact Dart SDK 2.14.3 Flutter SDK 2.5.2 photos 0.3.48+258 dependencies: - alice 0.2.4 [flutter http dio flutter_local_notifications rxdart path_provider permission_handler package_info_plus open_file sensors share chopper better_player collection] - animate_do 2.0.0 [flutter] - archive 3.1.2 [crypto path] - background_fetch 1.0.1 [flutter] - bip39 1.0.6 [pointycastle hex crypto] - cached_network_image 3.0.0 [flutter flutter_cache_manager octo_image] - chewie 1.2.2 [cupertino_icons flutter provider video_player wakelock] - computer 2.0.0 [meta] - confetti 0.6.0 [flutter vector_math] - connectivity 3.0.6 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web] - crisp 0.1.6 [flutter url_launcher flutter_inappwebview] - cupertino_icons 1.0.3 - device_info 2.0.2 [flutter device_info_platform_interface] - dio 4.0.0 [http_parser path] - dots_indicator 2.0.0 [flutter] - email_validator 2.0.1 - event_bus 2.0.0 - exif 3.0.0 [args collection convert sprintf] - expansion_tile_card 2.0.0 [flutter] - extended_image 5.1.2 [extended_image_library flutter meta] - firebase_core 1.7.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 10.0.8 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - fk_user_agent 2.0.1 [flutter] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_cache_manager 3.1.0 [clock collection file flutter http image path path_provider pedantic rxdart sqflite uuid] - flutter_datetime_picker 1.5.1 [flutter] - flutter_easyloading 3.0.0 [flutter flutter_spinkit] - flutter_email_sender 5.0.2 [flutter] - flutter_image_compress 1.1.0 [flutter] - flutter_inappwebview 5.3.2 [flutter] - flutter_local_notifications 8.2.0 [flutter flutter_local_notifications_platform_interface platform timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection meta path typed_data vector_math] - flutter_password_strength 0.1.6 [flutter] - flutter_secure_storage 4.2.0 [meta flutter] - flutter_sodium 0.2.0 [flutter ffi] - flutter_typeahead 3.2.1 [flutter flutter_keyboard_visibility] - flutter_windowmanager 0.2.0 [flutter] - fluttercontactpicker 4.4.0 [flutter contact_picker_platform_interface contact_picker_web] - fluttertoast 8.0.7 [flutter flutter_web_plugins] - google_nav_bar 5.0.5 [flutter] - image 3.0.2 [archive meta xml] - image_editor 1.0.1 [flutter] - implicitly_animated_reorderable_list 0.4.0 [flutter async meta] - in_app_purchase 0.5.2 [flutter json_annotation meta collection] - intl 0.17.0 [clock path] - like_button 2.0.2 [flutter] - loading_animations 2.2.0 [flutter] - local_auth 1.1.6 [flutter flutter_plugin_android_lifecycle intl meta platform] - logging 1.0.1 - motionphoto 0.0.1 [flutter] - move_to_background 1.0.2 [flutter] - open_file 3.2.1 [flutter ffi] - package_info_plus 1.3.0 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web] - page_transition 2.0.2 [flutter] - path_provider 2.0.2 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows] - pedantic 1.11.1 - photo_manager 1.3.6 [flutter] - photo_view 0.12.0 [flutter] - pie_chart 5.0.0 [flutter] - pinput 1.2.2 [flutter] - provider 6.0.1 [collection flutter nested] - quiver 3.0.1 [matcher] - receive_sharing_intent 1.4.5 [flutter] - scrollable_positioned_list 0.2.2 [flutter collection] - sentry 5.1.0 [http meta stack_trace uuid] - share_plus 2.2.0 [meta mime flutter share_plus_platform_interface share_plus_linux share_plus_macos share_plus_windows share_plus_web] - shared_preferences 2.0.6 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows] - sqflite 2.0.0+3 [flutter sqflite_common path] - sqflite_migration 0.3.0 [flutter sqflite] - super_logging 1.3.4 [flutter package_info_plus device_info logging intl path path_provider sentry_flutter] - syncfusion_flutter_core 19.2.49 [vector_math flutter] - syncfusion_flutter_sliders 19.2.49 [flutter intl syncfusion_flutter_core] - uni_links 0.5.1 [flutter uni_links_platform_interface uni_links_web] - url_launcher 6.0.4 [flutter url_launcher_platform_interface url_launcher_linux url_launcher_macos url_launcher_windows url_launcher_web] - uuid 3.0.4 [crypto] - video_player 2.2.5 [flutter meta video_player_platform_interface video_player_web html] - video_thumbnail 0.4.3 [flutter] - visibility_detector 0.2.0 [flutter] - wallpaper_manager_flutter 0.0.2 [flutter] dev dependencies: - flutter_launcher_icons 0.9.0 [args image path yaml] - flutter_native_splash 1.1.8+4 [image meta path xml yaml universal_io] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] - lints 1.0.1 dependency overrides: - flutter_local_notifications 8.2.0 [flutter flutter_local_notifications_platform_interface platform timezone] - provider 6.0.1 [collection flutter nested] transitive dependencies: - args 2.0.0 - async 2.8.1 [collection meta] - better_player 0.0.73 [flutter cupertino_icons wakelock pedantic meta flutter_widget_from_html_core visibility_detector path_provider collection xml] - boolean_selector 2.1.0 [source_span string_scanner] - characters 1.1.0 - charcode 1.3.1 - chopper 4.0.1 [http meta logging] - clock 1.1.0 - collection 1.15.0 - connectivity_for_web 0.4.0 [connectivity_platform_interface flutter_web_plugins flutter] - connectivity_macos 0.2.0 [flutter] - connectivity_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - contact_picker_platform_interface 4.4.0 [flutter meta plugin_platform_interface] - contact_picker_web 4.4.0 [flutter flutter_web_plugins js contact_picker_platform_interface] - convert 3.0.1 [typed_data] - crypto 3.0.1 [collection typed_data] - csslib 0.17.1 [source_span] - device_info_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - extended_image_library 3.1.0 [crypto flutter http_client_helper path path_provider] - fake_async 1.2.0 [clock collection] - ffi 1.1.1 - file 6.1.1 [meta path] - firebase_core_platform_interface 4.0.1 [collection flutter meta plugin_platform_interface] - firebase_core_web 1.1.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging_platform_interface 3.0.6 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 2.0.6 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - flutter_blurhash 0.6.0 [flutter meta pedantic] - flutter_keyboard_visibility 5.0.3 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter] - flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface] - flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter] - flutter_local_notifications_platform_interface 4.0.1 [flutter plugin_platform_interface] - flutter_plugin_android_lifecycle 2.0.2 [flutter] - flutter_spinkit 5.0.0 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math] - flutter_widget_from_html_core 0.6.2 [csslib flutter html] - hex 0.2.0 - html 0.15.0 [csslib source_span] - http 0.13.3 [async http_parser meta path pedantic] - http_client_helper 2.0.2 [http] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - js 0.6.3 - json_annotation 4.1.0 [meta] - matcher 0.12.10 [stack_trace] - meta 1.7.0 - mime 1.0.0 - nested 1.0.0 [flutter] - octo_image 1.0.0+1 [flutter flutter_blurhash] - package_info_plus_linux 1.0.3 [package_info_plus_platform_interface flutter path] - package_info_plus_macos 1.2.0 [flutter] - package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface] - package_info_plus_web 1.0.4 [flutter flutter_web_plugins http meta package_info_plus_platform_interface] - package_info_plus_windows 1.0.4 [package_info_plus_platform_interface ffi flutter win32] - path 1.8.0 - path_provider_linux 2.0.0 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 2.0.0 [flutter] - path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface] - path_provider_windows 2.0.1 [path_provider_platform_interface meta path flutter ffi win32] - permission_handler 8.2.2 [flutter meta permission_handler_platform_interface] - permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface] - petitparser 4.3.0 [meta] - platform 3.0.0 - plugin_platform_interface 2.0.0 [meta] - pointycastle 3.4.0 [collection convert js] - process 4.2.1 [file path platform] - rxdart 0.27.2 - sensors 2.0.3 [flutter] - sentry_flutter 5.1.0 [flutter flutter_web_plugins sentry package_info_plus] - share 2.0.4 [meta mime flutter] - share_plus_linux 2.0.4 [share_plus_platform_interface file flutter meta url_launcher] - share_plus_macos 2.0.2 [share_plus_platform_interface flutter] - share_plus_platform_interface 2.0.1 [flutter meta mime plugin_platform_interface] - share_plus_web 2.0.4 [share_plus_platform_interface url_launcher flutter flutter_web_plugins meta] - share_plus_windows 2.0.3 [share_plus_platform_interface flutter meta url_launcher] - shared_preferences_linux 2.0.0 [flutter file meta path path_provider_linux shared_preferences_platform_interface] - shared_preferences_macos 2.0.0 [shared_preferences_platform_interface flutter] - shared_preferences_platform_interface 2.0.0 [flutter] - shared_preferences_web 2.0.0 [shared_preferences_platform_interface flutter flutter_web_plugins meta] - shared_preferences_windows 2.0.0 [shared_preferences_platform_interface flutter file meta path path_provider_platform_interface path_provider_windows] - sky_engine 0.0.99 - source_span 1.8.1 [collection path term_glyph] - sprintf 6.0.0 - sqflite_common 2.0.0+2 [synchronized path meta] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - string_scanner 1.1.0 [charcode source_span] - synchronized 3.0.0 - term_glyph 1.2.0 - test_api 0.4.2 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - timezone 0.8.0 [path] - typed_data 1.3.0 [collection] - uni_links_platform_interface 1.0.0 [flutter plugin_platform_interface] - uni_links_web 0.1.0 [flutter flutter_web_plugins uni_links_platform_interface] - universal_io 2.0.4 [collection crypto meta typed_data] - url_launcher_linux 2.0.0 [flutter] - url_launcher_macos 2.0.0 [flutter] - url_launcher_platform_interface 2.0.3 [flutter plugin_platform_interface] - url_launcher_web 2.0.0 [url_launcher_platform_interface meta flutter flutter_web_plugins] - url_launcher_windows 2.0.0 [flutter] - vector_math 2.1.0 - video_player_platform_interface 4.2.0 [flutter flutter_test meta] - video_player_web 2.0.4 [flutter flutter_web_plugins meta video_player_platform_interface] - wakelock 0.5.6 [flutter meta wakelock_macos wakelock_platform_interface wakelock_web wakelock_windows] - wakelock_macos 0.4.0 [flutter flutter_web_plugins wakelock_platform_interface] - wakelock_platform_interface 0.3.0 [flutter meta] - wakelock_web 0.4.0 [flutter flutter_web_plugins js wakelock_platform_interface] - wakelock_windows 0.2.0 [flutter wakelock_platform_interface win32] - win32 2.0.5 [ffi] - xdg_directories 0.2.0 [meta path process] - xml 5.3.0 [collection meta petitparser] - yaml 3.1.0 [collection source_span string_scanner] ```