Code Monkey home page Code Monkey logo

Comments (12)

mikehardy avatar mikehardy commented on June 15, 2024 1

There was a problem with intent handling and splash screens etc in the react-native-firebase repo, resolved with some specific steps in AndroidManifest to make the intent go to the right place crazycodeboy/react-native-splash-screen#289 (comment) - no idea at all if this applies here but if someone could confirm that they definitely don't have splash screens eating the launch intent, that might help.

from react-native-notifee.

ja-bravo avatar ja-bravo commented on June 15, 2024

Same here, can't get getInitialNotification to return anything other than null in dev mode.
Everything else seems to work just fine, including background and foreground notifications but this here is a blocker for my company right now.

 useEffect(() => {
    messaging()
      .registerForRemoteNotifications()
      .then(r => {
        const granted = messaging().requestPermission();
        messaging().subscribeToTopic('developers');
        if (granted) {
          notifee
            .getInitialNotification()
            .then(initial => {
              if (initial) {
                console.log('Initial');
                console.log(initial);
              } else {
                console.log('no initial notification');
              }
            })
            .catch(e => console.log(e));
        } 
      });
  }, []);

from react-native-notifee.

kperreau avatar kperreau commented on June 15, 2024

Same problem for me, i can't buying the package if this feature is not working.
Trying to get the initial notification from remote (firebase Messaging) and always return null if i open app from notification when app is killed.
Worste, if app is in background (not killed), i can't reach the event getInitialNotification().

  • React-Native 61.5 (full hook, stateless)
  • Hermes
  • Tested with a real device connected (samsung s8+) in debug mode

from react-native-notifee.

Ehesp avatar Ehesp commented on June 15, 2024

Hey all

Thanks for the feedback - @mikehardy we actually implemented the initial notifications totally different to RNFB :D

Can you guys please show what notification options you're using to display the notification? When a pressAction is provided to the body/actions, and that press action causes an open of the app, that's when we save the notification into it's initial state, hence knowing the options would help massively :)

We'll be sorting this as priority so don't worry!

from react-native-notifee.

Ehesp avatar Ehesp commented on June 15, 2024

Also it's worth mentioning (does mention in the docs but maybe not obvious enough?), that once a call to getInitialNotification is called it is then cleared, so if there's a "double" mount/call that could be a problem.

Also @ja-bravo based on your code snippet, there is a couple of general issues:

  1. getInitialNotification has no impact on whether they're registered for notification or have them granted.
  2. You have nested promises, and some calls which do not wait for promises so your code may not be even working as expected. A better example would be:
function App() {
  async function bootstrap() {
    const initialNotification = await notifee.getInitialNotification();

    if (initialNotification) {
      // Do something
    }

    await messaging().registerForRemoteNotifications();
    const granted = await messaging().requestPermission();
    await messaging().subscribeToTopic("developers");
    // etc
  }

  useEffect(() => {
    bootstrap().catch(e => console.error(e));
  }, []);
}

In your example, granted will always be true because you're not waiting for the result, so granted = Promise, which is a truthy value :)

from react-native-notifee.

kperreau avatar kperreau commented on June 15, 2024

Hey all

Thanks for the feedback - @mikehardy we actually implemented the initial notifications totally different to RNFB :D

Can you guys please show what notification options you're using to display the notification? When a pressAction is provided to the body/actions, and that press action causes an open of the app, that's when we save the notification into it's initial state, hence knowing the options would help massively :)

We'll be sorting this as priority so don't worry!

I'ts not a local notification but a remote.
I have no pressAction option, just clicking on the notification.

If it can help, yes i'm using react-native-splash-screen.

Json notification exemple:

{
  "message": {
    "token": "XXXXX",
    "data": {
      "type": "newComment",
    	"photoID": "XXXXX",
	    "fromUserID": "XXXXX"
    },
    "notification": {
      "title": "Jhon commented your BeReal",
      "body": "test"
    },
    "apns": {
      "headers": {
        "apns-priority": "5"
      },
      "payload": {
        "aps": {
          "thread-id": "XXXXX"
        }
      }
    },
    "android": {
      "priority": "normal",
      "notification": {
        "channel_id": "default",
        "icon": "ic_notification"
      }
    },
    "fcm_options": {
      "analytics_label": "newComment"
    }
  }
}

from react-native-notifee.

Ehesp avatar Ehesp commented on June 15, 2024

Conscious there could be different situations going on here...

@kperreau Notifee only manages it's own notifications, not those which have been created via the notification payload, which the system creates automatically. If you check out the FCM guide it suggests to send the data over via the FCM payload and construct the notification manually (allowing for Notifee functionality to exist).

That being said, in theory we could also hook into "external" notifications and also manage them (e.g. checking for actions, providing default "press" behaviour).

from react-native-notifee.

ja-bravo avatar ja-bravo commented on June 15, 2024

Thanks for the answer @Ehesp. I copy-pasted that from the RNFB messaging documentation without double-checking, my bad.

We still can't get it to work on our app. We're not using react-native-splash-screen.

const AppContent = () => {
  async function bootstrap() {
    const initialNotification = await notifee.getInitialNotification();
    if (initialNotification) {
      console.log('initial notification'); // Never reaches here
      console.log(initialNotification);
    }

    await messaging().registerForRemoteNotifications();
    const granted = await messaging().requestPermission();
    console.log(`granted: ${granted}`); // Logs granted: true
    if (granted) {
      await messaging().subscribeToTopic('developers');
      console.log('sub to developers');
      messaging().onMessage(onMessageReceived); // Works perfectly, we can display the notification using notifee
    }
  }

  useEffect(() => {
    console.log('Run bootstrap');
    bootstrap().catch(e => console.log(e)); // No error gets logged
  }, []);
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName={SCREENS.Loading} headerMode="none">
        <Stack.Screen name={SCREENS.Loading} component={LoadingScreen} />
        <Stack.Screen name={SCREENS.Landing} component={LandingScreen} />

        <Stack.Screen name="AppStack" component={AppStack} />
      </Stack.Navigator>
    </NavigationContainer>
  );
};

const App = () => {
  return (
      <ApolloProvider client={apolloClient}>
        <AppProvider>
          <AppContent />
        </AppProvider>
      </ApolloProvider>
  );
};

I've tried sending the notification with both the data and notification fields

 const message = {
      topic: 'developers',
      notification: {
        title,
        body,
      },
    };

 const message = {
      topic: 'developers',
      data: {
        title,
        body,
      },
    };

The one with the notification field gets received with the app killed/in the background but getInitialNotification returns null.

The one with the data field gets received with the app killed/in the background if I use messaging().setBackgroundMessageHandler() and notifee.onBackgroundEvent() and I can display a local notification but it won't open the app once it's tapped.

Most likely there's just something that it's not clicking for me 😅

from react-native-notifee.

Ehesp avatar Ehesp commented on June 15, 2024

and I can display a local notification but it won't open the app once it's tapped.

By default, it doesn't as it's fully in your control. Have you read these docs?

Notifee does not provide any default interaction behaviour when a user presses a notification. The Android guidelines suggest a notification should always open the application when pressed. In React Native, we have multiple options to exactly how the application opens.

You need to specify a press action, and if that press action causes the app to open, the initial notification will be set ready to be consumed.

from react-native-notifee.

Ehesp avatar Ehesp commented on June 15, 2024

Closing this one - please let me know if you have issues after going through the above points.

from react-native-notifee.

rajnishcoder avatar rajnishcoder commented on June 15, 2024

There was a problem with intent handling and splash screens etc in the react-native-firebase repo, resolved with some specific steps in AndroidManifest to make the intent go to the right place crazycodeboy/react-native-splash-screen#289 (comment) - no idea at all if this applies here but if someone could confirm that they definitely don't have splash screens eating the launch intent, that might help.

Dosn't have react-native-splash-screen still getInitialNotification doesn't work.

from react-native-notifee.

mikehardy avatar mikehardy commented on June 15, 2024

@rajnishcoder you quoted my question but did not answer. My question was a general question "splash screens" not just that module. Do you have any activity in AndroidManifest.xml set as LAUNCHER other than your MainActivity? That's the important part.

from react-native-notifee.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.