Skip to content

🐛 [firebase_messaging] getInitialMessage returns null on iOS #9462

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

Closed
Tom3652 opened this issue Sep 3, 2022 · 7 comments
Closed

🐛 [firebase_messaging] getInitialMessage returns null on iOS #9462

Tom3652 opened this issue Sep 3, 2022 · 7 comments
Labels
closed-by-bot resolution: no-response Customer did not respond after some time. Stale Issue with no recent activity type: bug Something isn't working

Comments

@Tom3652
Copy link

Tom3652 commented Sep 3, 2022

Bug report

Describe the bug

I am calling RemoteMessage? message = await FirebaseMessaging.instance.getInitialMessage(); on my app to open a specific page when the user clicks on the push notification.

On Android the message var above is not null and the page is pushed.
On iOS, the message var above is null when the user opens the app after touching a push notification.

I am using the firebase_messaging: 13.0.0 version.

Steps to reproduce

Steps to reproduce the behavior:

  1. Setup Firebase FCM to work with iOS
  2. Run the sample code
  3. Send a remote notification
  4. Tap on the notification on your device with the app terminated
  5. See that it doesn't push the new page

Expected behavior

The method should not return null as it is done on Android when there is an actual RemoteMessage.

Sample project

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';


Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(const TestApp());
}

class TestApp extends StatelessWidget {
  const TestApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: HomePage()
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  Future<void> test() async {
    RemoteMessage? message = await FirebaseMessaging.instance.getInitialMessage();
    if (message != null) {
      Navigator.push(context, MaterialPageRoute(builder: (ctx) =>
          Scaffold(body: Center(
            child: Text("Page pushed from getInitialMessage"),),)));
    }
  }

  @override
  void initState() {
    test();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold();
  }
}

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.0, on macOS 12.5.1 21G83 darwin-x64, locale fr-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.70.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

@Tom3652 Tom3652 added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Sep 3, 2022
@Tom3652
Copy link
Author

Tom3652 commented Sep 5, 2022

I must say that it's working half of the time on iOS.

Yesterday i could see that it's working on 1/2 notifications in release mode.

I am sending push notifications from my server with the admin sdk in python.
I have setup the notification and the data in the RemoteMessage the same way for Android and iOS.

@darshankawar darshankawar added the triage Issue is currently being triaged. label Sep 5, 2022
@darshankawar
Copy link

@Tom3652
Can you take a look at this PR #9292, wherein, the plugin example was updated to confirm that messaging handlers work as expected.

I had also used the plugin example and verified that, in terminated state, when a notification is triggered using the script added in the plugin and run using node js, the notification is received and tapping on it directs the user towards an app screen.

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Sep 5, 2022
@Tom3652
Copy link
Author

Tom3652 commented Sep 9, 2022

Hey @darshankawar, it's working with the PR and also in my app (half of the time) so i don't know what else to try.
Note : i have checked the PR and i see it fixes especially background messaging not invoked and onMessageOpenedApp (both methods that always worked in my app)

I am guessing there is some race condition maybe using getInitialMessage() from a terminated state but i can't reproduce it 100% so... It's not a blocking feature in my app either but i prefer raise the ticket in case there is something beneath.

I will try to catch the error if there is any

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Sep 9, 2022
@darshankawar
Copy link

I am guessing there is some race condition maybe using getInitialMessage() from a terminated state

Are you using any community plugin which might be conflicting with messaging's notification ? like, flutter_apns ?
This could be something you can also look and see if that' really the case.

Considering the fact that the behavior is not consistent everytime and the plugin example does clear the notion that all handlers actually works, maybe this has something to do with an external factor / dependency.

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Sep 9, 2022
@hatemragab
Copy link

I have run the example provided with the package and same problem!

@google-oss-bot
Copy link

Hey @Tom3652. 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 google-oss-bot added the Stale Issue with no recent activity label Sep 26, 2022
@google-oss-bot
Copy link

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

@Tom3652 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.

@darshankawar darshankawar added resolution: no-response Customer did not respond after some time. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. triage Issue is currently being triaged. labels Oct 5, 2022
@firebase firebase locked and limited conversation to collaborators Nov 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed-by-bot resolution: no-response Customer did not respond after some time. Stale Issue with no recent activity type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants