skip to Main Content

Notification permission denied

[Error: Exception in HostObject::get(propName:RNFBMessagingModule):
java.lang.NullPointerException: Firebase Messaging component is not
present]

I used different methods but still issues is there. In code we used this package

@react-native-firebase/messaging 

2

Answers


  1. Chosen as BEST ANSWER

    Resolved with below solution :

    <service android:name="com.google.firebase.components.ComponentDiscoveryService" android:directBootAware="true" android:exported="false" >

    <meta-data android:name="com.google.firebase.components:com.google.firebase.messaging.FirebaseMessagingRegistrar" android:value="com.google.firebase.components.ComponentRegistrar" />

    <meta-data android:name="com.google.firebase.components:com.google.firebase.installations.FirebaseInstallationsRegistrar" android:value="com.google.firebase.components.ComponentRegistrar" /> </service>


  2. please considering going through following check points.

    Configure Firebase with Android credentials

    To allow Firebase on Android to use the credentials, the
    google-services plugin must be enabled on the project. This requires
    modification to two files in the Android directory.

    First, add the google-services plugin as a dependency inside of your
    /android/build.gradle file:

    buildscript {
      dependencies {
        // ... other dependencies
        // NOTE: if you are on react-native 0.71 or below, you must not update
        //       the google-services plugin past version 4.3.15 as it requires gradle >= 7.3.0
        classpath 'com.google.gms:google-services:4.4.1'
        // Add me --- /
      }
    }
    

    Generating iOS credentials

    On the Firebase console, add a new iOS application and enter your
    projects details. The "iOS bundle ID" must match your local project
    bundle ID. The bundle ID can be found within the "General" tab when
    opening the project with Xcode.

    if all of above checks out then look for the core cause

    Android – Requesting permissions

    On Android API level 32 and below, you do not need to request user
    permission. This method can still be called on Android devices;
    however, and will always resolve successfully. For API level 33+ you
    will need to request the permission manually using either the built-in
    react-native PermissionsAndroid APIs or a related module such as
    react-native-permissions

      import {PermissionsAndroid} from 'react-native';
      PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
    

    iOS – Requesting permissions

    iOS prevents messages containing notification (or ‘alert’) payloads
    from being displayed unless you have received explicit permission from
    the user.

    import messaging from '@react-native-firebase/messaging';
    
    async function requestUserPermission() {
      const authStatus = await messaging().requestPermission();
      const enabled =
        authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
        authStatus === messaging.AuthorizationStatus.PROVISIONAL;
    
      if (enabled) {
        console.log('Authorization status:', authStatus);
      }
    }
    

    The permissions API for iOS provides much more fine-grain control over
    permissions and how they’re handled within your application. To learn
    more, view the advanced iOS Permissions documentation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search