React-native-push-notification: Using PushNotification.configure without firebase

Created on 28 Nov 2020  路  6Comments  路  Source: zo0r/react-native-push-notification

Question

Hello, I would like to call a function when the use click to a notification
I have looked in the other issues to answer this question. And I have seen many responses to this subject.

I need to use PushNotification.configure as well as onNotification: function

The problem and when I use this function I get the following error:

Default FirebaseApp is not initialized in this process

I only use local notifications so I don't have to install firebase.
Is there a way to call a function when the user clicks on a notification without using firebase?

Thank you

Most helpful comment

Did you at least read what I wrote ?

Can't be more precise:

   * - if you are not using remote notification or do not have Firebase installed, use this:
   *     requestPermissions: Platform.OS === 'ios'

All 6 comments

Hi,

Already answered and in the readme on .configure().

Regards,

Thanks for the answer

I have read the readme and if you talk about to not use .configure inside a component it's already the case. I use .configure inside index.js but same error

I've don't find any correct answer for this question. Do you have the ref please ?

Regards,

https://github.com/zo0r/react-native-push-notification#usage

  /**
   * (optional) default: true
   * - Specified if permissions (ios) and token (android and ios) will requested or not,
   * - if not, you must call PushNotificationsHandler.requestPermissions() later
   * - if you are not using remote notification or do not have Firebase installed, use this:
   *     requestPermissions: Platform.OS === 'ios'
   */
  requestPermissions: true,

It still does not answer my question. I can't .configure () because of the error Default FirebaseApp is not initialized in this process

I'm on Android

I call the whole .configure() in index.js like this:

import { AppRegistry, Platform } from 'react-native';
import App from './App';
import PushNotificationIOS from "@react-native-community/push-notification-ios";
import PushNotification from "react-native-push-notification";

// Must be outside of any component LifeCycle (such as `componentDidMount`).
PushNotification.configure({
  // (optional) Called when Token is generated (iOS and Android)
  onRegister: function (token) {
    console.log("TOKEN:", token);
  },

  // (required) Called when a remote is received or opened, or local notification is opened
  onNotification: function (notification) {
    console.log("NOTIFICATION:", notification);

    // process the notification

    // (required) Called when a remote is received or opened, or local notification is opened
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  },

  // (optional) Called when Registered Action is pressed and invokeApp is false, if true onNotification will be called (Android)
  onAction: function (notification) {
    console.log("ACTION:", notification.action);
    console.log("NOTIFICATION:", notification);

    // process the action
  },

  // (optional) Called when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. (iOS)
  onRegistrationError: function(err) {
    console.error(err.message, err);
  },

  // IOS ONLY (optional): default: all - Permissions to register.
  permissions: {
    alert: true,
    badge: true,
    sound: true,
  },

  // Should the initial notification be popped automatically
  // default: true
  popInitialNotification: true,

  /**
   * (optional) default: true
   * - Specified if permissions (ios) and token (android and ios) will requested or not,
   * - if not, you must call PushNotificationsHandler.requestPermissions() later
   * - if you are not using remote notification or do not have Firebase installed, use this:
   *     requestPermissions: Platform.OS === 'ios'
   */
  requestPermissions: true,
});
AppRegistry.registerComponent('foodguardian', () => App);

if (Platform.OS === 'web') {
  const rootTag = document.getElementById('root') || document.getElementById('main');
  AppRegistry.runApplication('foodguardian', { rootTag });
}



But got error Default FirebaseApp is not initialized in this process

Did you at least read what I wrote ?

Can't be more precise:

   * - if you are not using remote notification or do not have Firebase installed, use this:
   *     requestPermissions: Platform.OS === 'ios'

Ok it's working. Didn't see the answer in the commented code.

Thanks you

Was this page helpful?
0 / 5 - 0 ratings