所以我一直在尝试制作这个应用程序,但是由于某种原因,在关闭应用程序后,我似乎无法检测到来自Firebase控制台的通知(不在后台或前台工作正常)
这是一些相关文件。
componentDidMount() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification: Notification) => {
// Process your notification as required
// ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
});
this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {
// Process your notification as required
notification.android.setChannelId('test-channel')
console.log("I'm called haha", notification);
firebase.notifications().displayNotification(notification)
});
this.messageListener = firebase.messaging().onMessage((message) => {
bgMessaging(message)
})
}
componentWillUnmount() {
this.notificationDisplayedListener();
this.notificationListener();
}
android清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobalib">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
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>
<receiver android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionReceiver"
android:exported="true">
<intent-filter>
<action android:name="io.invertase.firebase.notifications.BackgroundAction"/>
</intent-filter>
</receiver>
</service>
<service
android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<activity
android:launchMode="singleTop"
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
index.js:
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging);
和最终的bgMesseging.js:
xport default (message: RemoteMessage) => {
// handle your message
const title = message.get
const notification = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle('My notification title')
.setBody('My notification body')
.setData({
key1: 'value1',
key2: 'value2',
});
notification
.android.setChannelId('test-channel')
firebase.notifications().displayNotification(notification)
console.log(message);
return Promise.resolve();
}
答案 0 :(得分:-1)
TL / dr表示只能检测到手机的品牌信息。
所以在通知的这一部分,Android并不是很好,但是我可以在其他方面对其进行自定义,以至于我喜欢它