You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similiar to #7389.
When receving a push notification with the app in background or quit state neither setBackgroundMessageHandler or onNotificationOpenedApp or getInitialNotification seem to work in iOS. This issue started after updating React Native from 0.68 to 0.71.13 and the rnfirebase packages from 14 to 18.4.
ps: app name hidden for security reasons, can be later provided if needed
importReactfrom'react';import{AppRegistry}from'react-native';importmessagingfrom'@react-native-firebase/messaging';importAppfrom'./App';import{nameasappName}from'./app.json';importNotificationsStorefrom'_mobx/notifications';import{log}from'_utils/logs';// register background handlermessaging().setBackgroundMessageHandler(asyncremoteMessage=>{const{newNotification}=NotificationsStore;//stores notification on devicenewNotification(remoteMessage);log('Message handled in the background!'+remoteMessage,'inapp');});functionHeadlessCheck({isHeadless}){if(isHeadless){console.log('isHeadless '+isHeadless);// App has been launched in the background by iOS, ignorereturnnull;}return<App/>;}AppRegistry.registerComponent(appName,()=>HeadlessCheck);
iOS
Click To Expand
ios/Podfile:
I'm not using Pods
I'm using Pods and my Podfile looks like:
require_relative'../node_modules/react-native/scripts/react_native_pods'require_relative'../node_modules/@react-native-community/cli-platform-ios/native_modules'require_relative'../node_modules/react-native-permissions/scripts/setup'platform:ios,min_ios_version_supportedprepare_react_native_project!setup_permissions(['AppTrackingTransparency',# 'BluetoothPeripheral',# 'Calendars','Camera',# 'Contacts',# 'FaceID',# 'LocationAccuracy',# 'LocationAlways','LocationWhenInUse','MediaLibrary',# 'Microphone',# 'Motion','Notifications','PhotoLibrary','PhotoLibraryAddOnly'# 'Reminders',# 'SpeechRecognition',# 'StoreKit'])# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded## To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`# ```js# module.exports = {# dependencies: {# ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),# ```flipper_config=FlipperConfiguration.disabledlinkage=ENV['USE_FRAMEWORKS']use_frameworks!:linkage=>:staticiflinkage != nilPod::UI.puts"Configuring Pod with #{linkage}ally linked Frameworks".greenendproject'xxx','Dev.Debug'=>:debug,'Dev.Release'=>:release,'Qa.Debug'=>:debug,'Qa.Release'=>:release,'Prod.Debug'=>:debug,'Prod.Release'=>:releasetarget'xxx'doconfig=use_native_modules!# Flags change depending on the env values.flags=get_default_flags()use_react_native!(:path=>config[:reactNativePath],# Hermes is now enabled by default. Disable by setting this flag to false.# Upcoming versions of React Native may rely on get_default_flags(), but# we make it explicit here to aid in the React Native upgrade process.:hermes_enabled=>flags[:hermes_enabled],:fabric_enabled=>flags[:fabric_enabled],# Enables Flipper.## Note that if you have use_frameworks! enabled, Flipper will not work and# you should disable the next line.:flipper_configuration=>flipper_config,# An absolute path to your application root.:app_path=>"#{Pod::Config.instance.installation_root}/..")target'xxx'doinherit!:complete# Pods for testingend# Enables Flipper.## Note that if you have use_frameworks! enabled, Flipper will not work and# you should disable the next line.#use_flipper!({ 'Flipper-Folly' => '2.6.10' })#use_flipper!({'Flipper' => '0.75.1', 'Flipper-Folly' => '2.5.3', 'Flipper-RSocket' => '1.3.1'})post_installdo |installer|
react_native_post_install(installer,# Set `mac_catalyst_enabled` to `true` in order to apply patches# necessary for Mac Catalyst builds:mac_catalyst_enabled=>false)__apply_Xcode_12_5_M1_post_install_workaround(installer)installer.pods_project.targets.eachdo |target|
iftarget.respond_to?(:product_type)andtarget.product_type == "com.apple.product-type.bundle"target.build_configurations.eachdo |config|
config.build_settings['CODE_SIGNING_ALLOWED']='NO'endendendendend
AppDelegate.m:
#import"AppDelegate.h"
#import"RNBootSplash.h"
#import"RNFBMessagingModule.h"
#import<React/RCTLinkingManager.h>
#import<Firebase.h>
#import<React/RCTBundleURLProvider.h>
#import<FBSDKCoreKit/FBSDKCoreKit-swift.h>
#import"RNQuickActionManager.h"@implementationAppDelegate
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
self.moduleName = @"xxx";
// You can add your custom initial props in the dictionary below.// They will be passed down to the ViewController used by React Native.
self.initialProps = [RNFBMessagingModule addCustomPropsToUserProps:nilwithLaunchOptions:launchOptions];
return [superapplication:application didFinishLaunchingWithOptions:launchOptions];
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#elsereturn [[NSBundlemainBundle] URLForResource:@"main"withExtension:@"jsbundle"];
#endif
}
/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.////// @see: https://reactjs.org/blog/2022/03/29/react-v18.html/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture)./// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
// Switch this bool to turn on and off the concurrent rootreturnfalse;
}
- (NSDictionary *)prepareInitialProps
{
NSMutableDictionary *initProps = [NSMutableDictionarynew];
#ifdef RCT_NEW_ARCH_ENABLED
initProps[kRNConcurrentRoot] = @([selfconcurrentRootEnabled]);
#endifreturn initProps;
}
- (BOOL)application:(UIApplication *)applicationopenURL:(NSURL *)urloptions:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
if ([[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]) {
returnYES;
}
if ([RCTLinkingManager application:application openURL:url options:options]) {
returnYES;
}
returnNO;
}
- (BOOL)application:(UIApplication *)applicationcontinueUserActivity:(nonnull NSUserActivity *)userActivityrestorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
- (void)application:(UIApplication *)applicationperformActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItemcompletionHandler:(void (^)(BOOL succeeded)) completionHandler {
[RNQuickActionManager onQuickActionPress:shortcutItem completionHandler:completionHandler];
}
// 猬囷笍 Add this before file @end
- (UIView *)createRootViewWithBridge:(RCTBridge *)bridgemoduleName:(NSString *)moduleNameinitProps:(NSDictionary *)initProps {
UIView *rootView = [supercreateRootViewWithBridge:bridge
moduleName:moduleName
initProps:initProps];
[RNBootSplash initWithStoryboard:@"BootSplash"rootView:rootView]; // 猬咃笍 initialize the splash screenreturn rootView;
}
@end
Environment
Click To Expand
react-native info output:
System:
OS: macOS 13.3
CPU: (8) arm64 Apple M1
Memory: 95.88 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.16.1 - /var/folders/ns/_hzr6fpj3rx927knyzwq6bf40000gn/T/yarn--1697639407519-0.11020800598023928/node
Yarn: 1.22.5 - /var/folders/ns/_hzr6fpj3rx927knyzwq6bf40000gn/T/yarn--1697639407519-0.11020800598023928/yarn
npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.13.0 - /Users/ruirigueira/.rvm/gems/ruby-3.0.0/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
Android SDK: Not Found
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9477386
Xcode: 14.3/14E222b - /usr/bin/xcodebuild
Languages:
Java: 11.0.14.1 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: ^0.71.13 => 0.71.13
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Issue
Similiar to #7389.
When receving a push notification with the app in background or quit state neither setBackgroundMessageHandler or onNotificationOpenedApp or getInitialNotification seem to work in iOS. This issue started after updating React Native from 0.68 to 0.71.13 and the rnfirebase packages from 14 to 18.4.
ps: app name hidden for security reasons, can be later provided if needed
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:index.js
:iOS
Click To Expand
ios/Podfile
:AppDelegate.m
:Environment
Click To Expand
react-native info
output:React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: