Я использовал реагировать-native-firebase в моем собственном проекте реакции [платформа Android], чтобы показать уведомление приложения. С помощью этой библиотеки я могу показывать уведомление, когда приложение находится в состоянии переднего плана / фона / закрыто.
Согласно документации по реагированию на родную базу firebase, onNotificationOpened должен срабатывать, когда приложение открывается нажатием на уведомление. Однако в моем случае этого не происходит, метод onNotificationOpened никогда не вызывается, а метод getInitialNotification всегда получает нулевое значение.
Я также использую библиотеку реагировать-родной-заставка-экран для отображения заставки.
Вот мой код от App.js >> componentDidMount ()
firebase.messaging().requestPermission()
.then(() => {
const myAppChannel = new firebase.notifications.Android.Channel('my-channel',
'my Channel', firebase.notifications.Android.Importance.Max)
.setDescription('my channel');
firebase.notifications().android.createChannel(myAppChannel);
this.messageListener = firebase.messaging().onMessage((message) => {
const {title, body} = message.data;
const notificationDisplay = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle(title)
.setBody(body)
.setData({
key1: 'value1',
key2: 'value2',
}).setSubtitle('notification')
.setSound('default');
notificationDisplay
.android.setChannelId('my-channel')
.android.setSmallIcon('ic_launcher')
.android.setAutoCancel(true).android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications().displayNotification(notificationDisplay);
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
//never gets called
console.info('onNotificationOpened was triggered on notification taped');
});
})
.catch(error => {
// User has rejected permissions
console.info("user rejected");
console.info(error);
});
AndroidManifest.xml
<uses-permission android:name = "android.permission.INTERNET" />
<uses-permission android:name = "android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name = "android.permission.CAMERA" />
<uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name = "android.permission.INTERNET" />
<uses-permission android:name = "android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name = "android.permission.VIBRATE" />
<application
android:name = ".MainApplication"
android:allowBackup = "true"
android:icon = "@mipmap/ic_launcher"
android:label = "@string/app_name"
android:theme = "@style/AppTheme">
<service android:name = "io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name = "com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name = "io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name = "com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name = "io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
<meta-data
android:name = "com.google.firebase.messaging.default_notification_channel_id"
android:value = "@string/default_notification_channel_id" />
<activity
android:name = ".SplashActivity"
android:label = "@string/app_name"
android:launchMode = "singleTop"
android:theme = "@style/SplashTheme">
<intent-filter>
<action android:name = "android.intent.action.MAIN" />
<category android:name = "android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name = ".MainActivity"
android:configChanges = "keyboard|keyboardHidden|orientation|screenSize"
android:exported = "true"
android:label = "@string/app_name"
android:launchMode = "singleTop"
android:windowSoftInputMode = "adjustResize" />
<activity android:name = "com.facebook.react.devsupport.DevSettingsActivity" />
</application>
ОБНОВИТЬ: Проблема была вызвана библиотекой реагировать-родной-заставка-экран, я смог исправить это после удаления библиотека React-native-splash-screen из проекта Android. Однако я все еще не уверен, как я могу сделать это при использовании реагировать-родной-заставка-экран.





Добавление intent-filter в MainActivity и click-action в JSON для уведомлений помогло мне.
<intent-filter>
<action android:name = ".MainActivity" />
<category android:name = "android.intent.category.DEFAULT" />
</intent-filter>
Уведомление JSON
{
"to":"ID",
"notification" : {
**"click_action" : ".MainActivity",**
"body": "Message Body",
"title" : "Call Status",
"sound": "default",
"badge":"5"
},
"data": {
"type": 1,
"body": "Message Body",
"title" : "Call Status"
}
}
Мой manifest.xml выглядит так
<application
tools:replace = "android:allowBackup"
android:name = ".MainApplication"
android:label = "@string/app_name"
android:icon = "@mipmap/ic_launcher"
android:allowBackup = "false"
android:theme = "@style/AppTheme">
<service android:name = "io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name = "com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name = "io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name = "com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<activity
android:name = ".SplashActivity"
android:theme = "@style/SplashTheme"
android:launchMode = "singleTop"
android:label = "@string/app_name">
<intent-filter>
<action android:name = "android.intent.action.MAIN" />
<category android:name = "android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name = ".MainActivity"
android:label = "@string/app_name"
android:screenOrientation = "portrait"
android:launchMode = "singleTop"
android:configChanges = "keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode = "adjustPan">
<intent-filter>
<action android:name = ".MainActivity" />
<category android:name = "android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name = "com.facebook.react.devsupport.DevSettingsActivity" />
</application>
Надеюсь это поможет
Здравствуйте, не могли бы вы проверить этот вопрос, пожалуйста, @Hariks stackoverflow.com/questions/57171787/…
@SelvesanMalakar Можете ли вы предложить альтернативу response-native-splash-screen?
Спасибо за ответ. Я удалил из своего проекта экран-заставку response-native-splash и выбрал другой подход для отображения экрана-заставки. Но я попробую. Я предполагаю, что у ios должна быть такая же проблема, пожалуйста, дайте мне знать, как вы решили для ios