Open Jeel-Bhad opened 1 month ago
At a minimum, please format your markdown into something readable. I would suggest making a Minimal, Reproducible Example to demonstrate what the issue is.
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.
Issue
I am using '@react-native-firebase/messaging' this package is completely works well in my android(react-native-app) but I am facing issue in my ios build - my build is generated successfully but after getting notification I am not able to perform any background task. my 1st task is to redirect my notification to specific page on notification tap my 2nd task is to update badge in background while coming new notification
my 2 function is not getting fired in ios while receiving notification let me show my code below my firebase payload for ios { "data": { "buildingId": "27", "buildingName": "Jeel", "childSubfolderId": "0", "diciplineId": "0", "folderid": "2", "groupId": "35", "isfrom": "SubFolder", "isgroup": "false", "ispage": "Chat", "messageId": "4066", "receiverId": "267", "receivername": "Jeel", "senderId": "271", "sendername": "Sherin M", "subfolderid": "55" }, "from": "810581931372", "messageId": "1722841496653586", "notification": { "body": "fgfg", "ios": { "badge": 18 }, "sound": "default", "title": "Sherin M" } }
1)task related to badge update-I want to make an API call index.js file import 'react-native-gesture-handler'; import {Alert, AppRegistry} from 'react-native'; import App from './App'; import {name as appName} from './app.json'; import messaging from '@react-native-firebase/messaging'; import notifee from '@notifee/react-native';
//Register background handler messaging().setBackgroundMessageHandler(async remoteMessage => { console.log('Message handled in the background!', remoteMessage); dispatch(unReadNotificationCntApi()).unwrap().then((res)=>{ notifee.setBadgeCount(res.data); }).catch((err)=>{ console.log(err); Alert.alert(err); }); });
2)I am not able to redirect my notification after tapping on it and I am calling this below function in my app.tsx file
export async function notificationListner() { const unsubscribe = messaging().onMessage(async remoteMessage => {
}
Describe your issue here
if I want to perform any API call inside the following function I am not able to do that. even I am not getting this console.log value after coming my notification. console.log('Message handled in the background!', remoteMessage); messaging().setBackgroundMessageHandler
for second issue I am not able to fire code inside messaging().onNotificationOpenedApp() function
Project Files
Javascript
import messaging from '@react-native-firebase/messaging'; import { setLocalStorageValue } from './helpers'; import { navigate } from '../navigations/RootNavigation'; import { Alert } from 'react-native'; import notifee from '@notifee/react-native' ; export async function requestUserPermission() { const authStatus = await messaging().requestPermission(); const enabled = authStatus === messaging.AuthorizationStatus.AUTHORIZED || authStatus === messaging.AuthorizationStatus.PROVISIONAL;
}
const getToken = async() =>{ try{ const token = await messaging().getToken(); token && await setLocalStorageValue({field: 'firebaseToken', data: token}); Alert.alert("token"+token) console.log(token); }catch{ console.log("Error getting token"); } }
export async function notificationListner() { const unsubscribe = messaging().onMessage(async remoteMessage => {
}
package.json
:{ "name": "taskxs", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "lint": "eslint .", "start": "react-native start", "test": "jest" }, "dependencies": { "@expo/react-native-action-sheet": "^4.0.1", "@fortawesome/fontawesome-svg-core": "^6.5.1", "@fortawesome/free-solid-svg-icons": "^6.5.1", "@fortawesome/react-native-fontawesome": "^0.3.0", "@microsoft/signalr": "^8.0.0", "@notifee/react-native": "^7.8.2", "@react-native-async-storage/async-storage": "^1.22.3", "@react-native-community/push-notification-ios": "^1.11.0", "@react-native-firebase/app": "^19.2.2", "@react-native-firebase/messaging": "^19.2.2", "@react-navigation/drawer": "^6.6.14", "@react-navigation/native": "^6.1.12", "@react-navigation/stack": "^6.3.28", "@reduxjs/toolkit": "^2.2.1", "axios": "^1.6.7", "i18next": "^23.10.1", "moment": "^2.30.1", "react": "18.2.0", "react-hook-form": "^7.51.0", "react-i18next": "^14.1.0", "react-native": "0.73.4", "react-native-element-dropdown": "^2.10.2", "react-native-gesture-handler": "^2.15.0", "react-native-image-picker": "^7.1.2", "react-native-localize": "^3.0.6", "react-native-pager-view": "^6.3.3", "react-native-paper": "^5.12.3", "react-native-reanimated": "^3.8.0", "react-native-render-html": "^6.3.4", "react-native-safe-area-context": "^4.9.0", "react-native-screens": "^3.29.0", "react-native-splash-screen": "^3.3.0", "react-native-svg": "^15.1.0", "react-native-toast-message": "^2.2.0", "react-redux": "^9.1.0", "rxjs": "^7.8.1" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@react-native/babel-preset": "0.73.21", "@react-native/eslint-config": "0.73.2", "@react-native/metro-config": "0.73.5", "@react-native/typescript-config": "0.73.1", "@types/react": "^18.2.6", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.6.3", "eslint": "^8.19.0", "jest": "^29.6.3", "prettier": "2.8.8", "react-test-renderer": "18.2.0", "typescript": "5.0.4" }, "engines": { "node": ">=18" } }
firebase.json
for react-native-firebase v6:AppDelegate.m
:import "AppDelegate.h"
import <React/RCTBundleURLProvider.h>
import
import
@implementation AppDelegate
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions { // Configure Firebase if ([FIRApp defaultApp] == nil) { [FIRApp configure]; }
// Set up Firebase Cloud Messaging if (@available(iOS 10.0, )) { [UNUserNotificationCenter currentNotificationCenter].delegate = self; UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge; [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError _Nullable error) { if (error != nil) { NSLog(@"Error requesting notification authorization: %@", error); } }]; } else { UIUserNotificationType allNotificationTypes = (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; [application registerUserNotificationSettings:settings]; }
[application registerForRemoteNotifications];
self.moduleName = @"TaskXS"; self.initialProps = @{};
return [super application:application didFinishLaunchingWithOptions:launchOptions]; }
(NSURL )sourceURLForBridge:(RCTBridge )bridge { return [self getBundleURL]; }
(NSURL *)getBundleURL {
if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
endif
}
// Implement didRegisterForRemoteNotificationsWithDeviceToken
// Implement didReceiveRemoteNotification for iOS 10 and above
// Implement userNotificationCenter willPresent notification for foreground notification display
(void)userNotificationCenter:(UNUserNotificationCenter )center willPresentNotification:(UNNotification )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { NSDictionary *userInfo = notification.request.content.userInfo;
// Display notification as alert, sound, and badge completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionBadge); }
// Implement userNotificationCenter didReceive response for background or closed app notification interaction
@end
info.plist file <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
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**: - [Yes ] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both issue only facing in iOS and my android app is working fine - **`react-native-firebase` version you're using that has this issue:** - `e.g@react-native-firebase/messaging": "^19.2.2", - **`Firebase` module(s) you're using that has the issue:** - `e.g. @react-native-firebase/messaging @react-native-firebase/app @notifee/react-native": "^7.8.2", - **Are you using `TypeScript`?** - `Y/N` & `VERSION` Y & "typescript": "5.0.4"
React Native Firebase
andInvertase
on Twitter for updates on the library.