[🐛] Bug/notification tap action issue and background updating badge issue in iOS my android is working fine #7958
Labels
blocked: customer-response
platform: ios
plugin: messaging
FCM only - ( messaging() ) - do not use for Notifications
Stale
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
:# N/A
{
"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
:// N/A
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <Firebase.h>
#import <FirebaseMessaging.h>
@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
{
[FIRMessaging messaging].APNSToken = deviceToken;
}
// Implement didReceiveRemoteNotification for iOS 10 and above
{
// Handle notification when app is in the background or inactive
completionHandler(UIBackgroundFetchResultNewData);
}
// 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
{
NSDictionary *userInfo = response.notification.request.content.userInfo;
// Handle notification when app is in the background or closed
completionHandler();
}
@EnD
info.plist file
CFBundleDevelopmentRegion en CFBundleDisplayName XS Project CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString $(MARKETING_VERSION) CFBundleSignature ???? CFBundleVersion $(CURRENT_PROJECT_VERSION) FirebaseAPIKey AIzaSyDe9iWCR6WrkUgjLSRXEtNPfqKjEInn2i8 FirebaseAppID 1:810581931372:ios:5ea0ad13ca45131fe5ef49 FirebaseMessagingAutoInitEnabled LSRequiresIPhoneOS NSAppTransportSecurity NSAllowsArbitraryLoads NSAllowsLocalNetworking NSCameraUsageDescription $(PRODUCT_NAME) would like to use your camera NSLocationWhenInUseUsageDescription $(PRODUCT_NAME) would like access to your Location NSPhotoLibraryAddUsageDescription $(PRODUCT_NAME) would like to use your photo library NSPhotoLibraryUsageDescription $(PRODUCT_NAME) would like access to your photo gallery UIBackgroundModes fetch processing remote-notification UILaunchStoryboardName LaunchScreen UIRequiredDeviceCapabilities armv7 UIRequiresFullScreen UISupportedInterfaceOrientations UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIViewControllerBasedStatusBarAppearanceAndroid
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:// N/A
android/app/build.gradle
:// N/A
android/settings.gradle
:// N/A
MainApplication.java
:// N/A
AndroidManifest.xml
:<!-- N/A -->
Environment
Click To Expand
react-native info
output:Platform that you're experiencing the issue on:
issue only facing in iOS and my android app is working fine
react-native-firebase
version you're using that has this issue:Firebase
module(s) you're using that has the issue:@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.The text was updated successfully, but these errors were encountered: