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
I configured it according to the document https://rnfirebase.io/messaging/usage#background--quit-state-messages and obtained the permissions, but setBackgroundMessageHandler seems to be only valid when the app is running. After the app is closed through the 'UI' slide, no notification will pop up, and it seems that Headless JS is not created.
For this reason, I also went to the AndroidManifest file to check, but did not find the added service. Do I need to add it manually? If so, I hope it can be reflected in the document
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
apply plugin: "com.google.gms.google-services"/** * This is the configuration block to customize your React Native Android app. * By default you don't need to apply any configuration, just uncomment the lines you need.*/
react {
/* Folders */// The root of your project, i.e. where "package.json" lives. Default is '../..'// root = file("../../")// The folder where the react-native NPM package is. Default is ../../node_modules/react-native// reactNativeDir = file("../../node_modules/react-native")// The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen// codegenDir = file("../../node_modules/@react-native/codegen")// The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js// cliFile = file("../../node_modules/react-native/cli.js")/* Variants */// The list of variants to that are debuggable. For those we're going to// skip the bundling of the JS bundle and the assets. By default is just 'debug'.// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.// debuggableVariants = ["liteDebug", "prodDebug"]/* Bundling */// A list containing the node command and its flags. Default is just 'node'.// nodeExecutableAndArgs = ["node"]//// The command to run when bundling. By default is 'bundle'// bundleCommand = "ram-bundle"//// The path to the CLI configuration file. Default is empty.// bundleConfig = file(../rn-cli.config.js)//// The name of the generated asset file containing your JS bundle// bundleAssetName = "MyApplication.android.bundle"//// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'// entryFile = file("../js/MyApplication.android.js")//// A list of extra flags to pass to the 'bundle' commands.// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle// extraPackagerArgs = []/* Hermes Commands */// The hermes compiler command to run. By default it is 'hermesc'// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"//// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"// hermesFlags = ["-O", "-output-source-map"]/* Autolinking */
autolinkLibrariesWithApp()
}
/** * Set this to true to Run Proguard on Release builds to minify the Java bytecode.*/def enableProguardInReleaseBuilds =true/** * The preferred build flavor of JavaScriptCore (JSC) * * For example, to use the international variant, you can use: * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` * * The international variant includes ICU i18n library and necessary data * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that * give correct results when using with locales other than en-US. Note that * this variant is about 6MiB larger per architecture than default.*/def jscFlavor ='org.webkit:android-jsc:+'
android {
ndkVersion rootProject.ext.ndkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion
namespace "com.purse"
defaultConfig {
applicationId "com.purse"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
implementation 'com.google.mlkit:barcode-scanning:17.2.0'if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
}
packagecom.purseimportandroid.app.Applicationimportcom.facebook.react.PackageListimportcom.facebook.react.ReactApplicationimportcom.facebook.react.ReactHostimportcom.facebook.react.ReactNativeHostimportcom.facebook.react.ReactPackageimportcom.facebook.react.defaults.DefaultNewArchitectureEntryPoint.loadimportcom.facebook.react.defaults.DefaultReactHost.getDefaultReactHostimportcom.facebook.react.defaults.DefaultReactNativeHostimportcom.facebook.react.soloader.OpenSourceMergedSoMappingimportcom.facebook.soloader.SoLoaderclassMainApplication : Application(), ReactApplication {
overrideval reactNativeHost:ReactNativeHost=object:DefaultReactNativeHost(this) {
overridefungetPackages(): List<ReactPackage> =PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:// add(MyReactNativePackage())
}
overridefungetJSMainModuleName(): String="index"overridefungetUseDeveloperSupport(): Boolean=BuildConfig.DEBUGoverrideval isNewArchEnabled:Boolean=BuildConfig.IS_NEW_ARCHITECTURE_ENABLEDoverrideval isHermesEnabled:Boolean=BuildConfig.IS_HERMES_ENABLED
}
overrideval reactHost:ReactHost
get() = getDefaultReactHost(applicationContext, reactNativeHost)
overridefunonCreate() {
super.onCreate()
SoLoader.init(this, OpenSourceMergedSoMapping)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
}
}
mikehardy
changed the title
[🐛] setBackgroundMessageHandler 仅在应用运行时才有效
[🐛] setBackgroundMessageHandler is only valid when the app is running #8188
Dec 12, 2024
mikehardy
changed the title
[🐛] setBackgroundMessageHandler is only valid when the app is running #8188
[🐛] setBackgroundMessageHandler is only valid when the app is running
Dec 12, 2024
Please understand this is an English-speaking repository. I have used google translate to auto-translate your title and description and included those translations. I can only work with English, apologies.
I have just reproduced recently that this could have a problem if you are using react-native 0.76.0 through 0.76.4 with old architecture / newArchEnabled=false in gradle.properties.
I am 100% sure that react-native-firebase is working with old arch and new arch with headlessJS in react-native 0.76.5 because I made a reproducer that helped troubleshoot the issue both with and without new architecture.
If you set the bundle names to ones that you can create firebase console project files for and are connected correctly via FCM->APNs with a configured bundle ID in Apple's Developer Console that has the APNs certificates set correctly in the Firebase console, the make-demo.sh now has a button that will send a message back to the app with a delay for FCM setBackgroungMessageHandler testing:
I include all that information because I want to be 100% clear that this is something that is very difficult to get correct - both configured correctly in app and server, and to get the actual JSON correct to send it etc.
Because of that I was very careful with my testing though, and I'm certain it works.
You should carefully watch adb logcat while you are testing, but given that I specifically test this case very carefully and have a reproducer app with all its parts linked above I believe this will be a project-specific problem for you, and won't be able to take any action unless you create a reproducer that demonstrates it.
I configured it according to the document https://rnfirebase.io/messaging/usage#background--quit-state-messages and obtained the permissions, but setBackgroundMessageHandler seems to be only valid when the app is running. After the app is closed through the 'UI' slide, no notification will pop up, and it seems that Headless JS is not created.
For this reason, I also went to the AndroidManifest file to check, but did not find the added service. Do I need to add it manually? If so, I hope it can be reflected in the document
我按照文档https://rnfirebase.io/messaging/usage#background--quit-state-messages 进行配置,权限也都获取到了,但是setBackgroundMessageHandler 似乎只在应用正在运行时有效,应用通过‘UI’滑动关闭后就不会弹出通知了,似乎也没有创建Headless JS。
为此,我还前往AndroidManifest文件中查看,没有发现添加的服务,是需要手动添加吗,如果是的话希望能在文档中体现
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:# N/A
AppDelegate.m
:// N/A
Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:android/app/build.gradle
:android/settings.gradle
:MainApplication.kt
:AndroidManifest.xml
:Environment
Click To Expand
react-native info
output: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
TypeScript
?Y/N
&VERSION
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: