Skip to content
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

docs: onNotificationOpenedApp & getInitialNotification not supported on IOS #616

Closed
arjendevos opened this issue Dec 14, 2022 · 14 comments
Closed
Assignees
Labels
needs-feedback Waiting on response to questions Type: Stale

Comments

@arjendevos
Copy link

React.useEffect(() => {
    requestUserPermission().then(() => {
      messaging()
        .getToken()
        .then((token) => {
          console.log("FCM Token:", token);
        });
    });

    messaging().onNotificationOpenedApp((remoteMessage) => {
      Alert.alert("Notification caused app to open from background state:", JSON.stringify(remoteMessage));
    });

    messaging()
      .getInitialNotification()
      .then((remoteMessage) => {
        if (remoteMessage) {
          Alert.alert("Notification caused app to open from quit state:", JSON.stringify(remoteMessage));
        }
      });

    const unsubscribe = messaging().onMessage(async (remoteMessage) => {
      Alert.alert("A new FCM message arrived!", JSON.stringify(remoteMessage));
    });

    return unsubscribe;
  }, []);

Before i installed notifee, it worked fine. Now it only fires the onMessage() function.

@arjendevos
Copy link
Author

Found the answer:
onNotificationOpenedApp and getInitialNotification from RNFB Messaging will no longer trigger as notifee will handle the event. Should not require any code changes to these RNFB event handlers, as events on Android will continue to work as normal

@arjendevos
Copy link
Author

Can't find the alternative though

@helenaford
Copy link
Member

ah yes, that's correct for iOS! Did you solve your issue?

@helenaford helenaford added the needs-feedback Waiting on response to questions label Dec 14, 2022
@arjendevos
Copy link
Author

@helenaford no, can't find the alternatives

@helenaford
Copy link
Member

sorry, could you elaborate? what do you mean by alternatives?

@arjendevos
Copy link
Author

@helenaford i need those 2 functions for both IOS and Android. If Notifee handles this now, how can i still use those 2 functions with Notifee?

@helenaford
Copy link
Member

@arjendevos for iOS and for android when notifications are displayed when the app is open, you need to use notifee event handlers

@arjendevos
Copy link
Author

@helenaford yeah i understand, but what can i use for when the app is closed?

@MustagheesButt
Copy link

@arjendevos From the Android Handling Interaction docs it says onForegroundEvent. And on iOS Handling Interaction docs, it says onBackgroundEvent.

I tried with both (on Android only), and it seems onBackgroundEvent is the alternate for both onNotificationOpenedApp and getInitialNotification. The following is in my index.js, and gets called when I click on the notification (app in background or killed state):

notifee.onBackgroundEvent(async ({ type, detail }) => {
  if (type === EventType.PRESS) {
    console.log("App opened from click");
  }
});

You should also check Notifee's getInitialNotification in App Open Events

@AnisDerbel
Copy link

@helenaford when pressing on a remote notification on IOS when the app in in background but not killed, it triggers onForegroundEvent instead of onBackgroundEvent, what is the status of this issue ? Thanks

@Avishayy
Copy link

@AnisDerbel Looks like this is intentional? See https://notifee.app/react-native/docs/events#app-open-events

getInitialNotification is deprecated on iOS in favour of the PRESS event received by the onForegroundEvent event handler

Meaning onForegroundEvent() is to be used to get the notification that opens the app, not onBackgroundEvent()

@AnisDerbel
Copy link

AnisDerbel commented Jan 12, 2023

@Avishayy you are right,That's what I did. I use onForegroundEvent for both app in background or killed for IOS and getInitialNotification (from react-native-firebase/messaging) for Android when app is killed and onNotificationOpenedApp (from react-native-firebase/messaging) when app is in background.

All is good

@helenaford
Copy link
Member

Adding this as a priority to update in docs

@helenaford helenaford self-assigned this Jan 12, 2023
@helenaford helenaford changed the title onNotificationOpenedApp & getInitialNotification don't work anymore after installing notifee on IOS (expo) docs: onNotificationOpenedApp & getInitialNotification don't work anymore after installing notifee on IOS (expo) Jan 12, 2023
@helenaford helenaford changed the title docs: onNotificationOpenedApp & getInitialNotification don't work anymore after installing notifee on IOS (expo) docs: onNotificationOpenedApp & getInitialNotification not supported on IOS Jan 12, 2023
@github-actions
Copy link

github-actions bot commented Feb 9, 2023

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 attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-feedback Waiting on response to questions Type: Stale
Projects
None yet
Development

No branches or pull requests

5 participants