Skip to content

馃敟馃悰馃敟 isHeadless iOS is buggy 馃敟馃悰馃敟聽#4163

Closed

Description

@OmarBasem

Issue

Describe your issue here

I used the isHeadless blocks of code from https://rnfirebase.io/messaging/usage#background-application-state to block the main App component being rendered on iOS when receiving a notification in KILLED state. So, it partly works. When a notification pops up on the screen, then I open it after few seconds (about 3 seconds) the App Component will render without a problem after opening the notification. But if I open the notification IMMEDIATELY the App Component will not render because the app gets opened at the same time it is returning null because of the isHeadless prop is true. So is there a way to fix this problem, or even better block Firebase from launching the app bundle on iOS when receiving notifications while app is KILLED (because anyway I use NotificationServiceExtension to handle iOS background/killed notifications so I do not need firebase for that).

Versions:

"@react-native-firebase/app": "^8.4.0",
 "@react-native-firebase/messaging": "^7.8.1",
"react-native": "^0.63.2",

Project Files

Javascript

Click To Expand

package.json:

# N/A

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • e.g. 5.4.3
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y/N & VERSION


Activity

  1. changed the title [-][馃悰] 馃敟馃悰馃敟 isHeadless iOS is buggy 馃敟馃悰馃敟[/-] [+]馃敟馃悰馃敟 isHeadless iOS is buggy 馃敟馃悰馃敟[/+] on Aug 27, 2020
  2. mikehardy commented on Aug 27, 2020

    @mikehardy
    Collaborator

    This is a complicated topic. If you've got a race condition (initially launched in background / no UI on a message, but then also tapped to bring to foreground) which condition is correct? It was headless. That's not wrong. It's not headless anymore, that's also true.

    I think the answer will be different for everyone. Does your project have side effects when <App/> is rendered? Can you eliminate those? Or only do them if https://reactnative.dev/docs/appstate says you are foreground?

    Why not be less fiddly in the native side on launch with iOS since iOS does not really have a headless state (vs Android) and use AppState instead? Maybe just with isHeadless as indicator it was a background launch, but without drastic app flow branches

  3. OmarBasem commented on Aug 28, 2020

    @OmarBasem
    Author

    @mikehardy I tried using AppState and few other techniques but nothing worked. Is there a way to stop firebase from launching the app while killed? Why is "didFinishLaunchingWithOptions" being called on the native side when receiving a notification while app is killed? I think this was not the behaviour in version 5.

  4. OmarBasem commented on Aug 28, 2020

    @OmarBasem
    Author

    So a temporary workaround is to avoid performing any network requests and other processing included in the componentDidMount method of the "HomeScreen" until app comes to foreground:

    async componentDidMount() {
            if (AppState.currentState !== 'background')
                this.didMount()
            else
                this.needsMounting = true
            AppState.addEventListener('change', (state) => {
                if (state === 'active' && this.needsMounting)
                    this.didMount()
            })
        }
    
  5. stale commented on Oct 4, 2020

    @stale

    Hello 馃憢, to help manage issues we automatically close stale issues.
    This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

    This issue will be closed in 15 days if no further activity occurs.
    Thank you for your contributions.

  6. added
    Type: StaleIssue has become stale - automatically added by Stale bot
    on Oct 4, 2020
  7. stale commented on Nov 1, 2020

    @stale

    Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: StaleIssue has become stale - automatically added by Stale bothelp: needs-triageIssue needs additional investigation/triaging.type: bugNew bug report

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions