Closed shubhanshubb closed 9 months ago
We can solved it by this export async function requestUserPermission() { let authStatus; if (Platform.OS === 'android') { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS, ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { authStatus = messaging.AuthorizationStatus.AUTHORIZED; } else { authStatus = messaging.AuthorizationStatus.DENIED; } } catch (error) { console.warn('Error requesting notification permission:', error); authStatus = messaging.AuthorizationStatus.DENIED; } } else { authStatus = await messaging().requestPermission(); }
const enabled = authStatus === messaging.AuthorizationStatus.AUTHORIZED || authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) { // console.log('Authorization status:', authStatus); GetFcmToken(); } }
Issue
Describe your issue here
I am not getting fcm Token in android after allowing notifications but I am getting fcmToken in Ios
Project Files
Javascript
import AsyncStorage from '@react-native-async-storage/async-storage'; import messaging from '@react-native-firebase/messaging'; import {PermissionsAndroid, Platform} from 'react-native';
export async function requestUserPermission() { let authStatus; if (Platform.OS === 'android') { authStatus = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS, ); } else { authStatus = await messaging().requestPermission(); } // const authStatus = await messaging().requestPermission(); const enabled = authStatus === messaging.AuthorizationStatus.AUTHORIZED || authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) { // console.log('Authorization status:', authStatus); GetFcmToken(); } }
async function GetFcmToken() { let fcmToken = await AsyncStorage.getItem('fcmToken'); console.log('the old token:', fcmToken); if (!fcmToken) { try { fcmToken = await messaging().getToken(); if (fcmToken) { console.log('new fcm token', fcmToken); await AsyncStorage.setItem('fcmToken', fcmToken); // dispatch(getDeviceTokenRequest()); } } catch (error) { console.log('fcm token error', error); } } else { if (fcmToken) { // dispatch(getDeviceTokenRequest()); } } }
package.json
:"dependencies": { "@invertase/react-native-apple-authentication": "^2.3.0", "@react-native-async-storage/async-storage": "^1.21.0", "@react-native-community/masked-view": "^0.1.11", "@react-native-firebase/app": "^18.8.0", "@react-native-firebase/auth": "^18.8.0", "@react-native-firebase/messaging": "^18.8.0", "@react-native-google-signin/google-signin": "^11.0.0", "@react-navigation/bottom-tabs": "^6.5.11", "@react-navigation/native": "^6.1.9", "@react-navigation/stack": "^6.3.20", "axios": "^1.6.5", "base-64": "^1.0.0", "date-fns": "^3.3.1", "deprecated-react-native-prop-types": "^5.0.0", "jwt-decode": "^4.0.0", "moment": "^2.30.1", "moment-timezone": "^0.5.44", "react": "18.2.0", "react-native": "0.73.2", "react-native-asset": "^2.1.1", "react-native-element-dropdown": "^2.10.1", "react-native-fast-image": "^8.6.3", "react-native-gesture-handler": "^2.14.1", "react-native-image-crop-picker": "^0.40.2", "react-native-linear-gradient": "^2.8.3", "react-native-localize": "^3.0.6", "react-native-phone-number-input": "^2.1.0", "react-native-progress": "^5.0.1", "react-native-push-notification": "^8.1.1", "react-native-reanimated": "^3.6.1", "react-native-safe-area-context": "^4.8.2", "react-native-screens": "^3.29.0", "react-native-share": "^10.0.2", "react-native-snap-carousel": "^3.9.1", "react-native-sound": "^0.11.2", "react-native-splash-screen": "^3.3.0", "react-native-store-version": "^1.4.1", "react-native-typewriter": "^0.7.0", "react-native-vector-icons": "^10.0.3", "socket.io-client": "^4.7.4" },
firebase.json
for react-native-firebase v6:iOS
Click To Expand
#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // 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`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```
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`
React Native Firebase
andInvertase
on Twitter for updates on the library.