我正在使用react- native -firebase库,当它们在后台时,我正在集思广益地定制我的通知,我试图按照文档操作,但没有用,有没有本机代码.java来处理通知?
发布于 2019-10-10 22:11:51
要自定义后台通知,可以将其添加到应用程序的索引中:
import { AppRegistry } from 'react-native'
import App from './App'
import { backgroundMessageNotificationHandler } from 'src/common/notifications'
AppRegistry.registerComponent('testApp', () => App)
AppRegistry.registerHeadlessTask(
'RNFirebaseBackgroundMessage',
() => backgroundMessageNotificationHandler)
backgroundMessageNotificationHandler可能是这样的:
export const backgroundMessageNotificationHandler = async (message: any) => {
const localNotification = new firebase.notifications.Notification().android
.setChannelId(androidNotificationsChannel.channelId)
.android.setSmallIcon('iconBlackAndWhite')
.android.setLargeIcon('iconBlackAndWhite')
.android.setPriority(firebase.notifications.Android.Priority.High)
.setNotificationId(message.messageId)
.setSound('default')
.setTitle(message.data.title)
.setBody(message.data.body)
.setData(message.data)
if (Platform.OS === 'android') {
createChannel()
}
firebase.notifications().displayNotification(localNotification)
return Promise.resolve()
}
请记住按照设置build.gralde、MainActivity和AndroidManifest的步骤进行操作。您可以按照以下帖子中指定的步骤进行操作:
https://stackoverflow.com/questions/58324413
复制相似问题