如何解决收到通知时 react-native-notifications 使应用程序崩溃
我正在使用 react-native-notifications 库通过消息云 Firebase 在我的应用程序中实现通知,我已遵循文档中的所有指南,
For react-native-notifications library
For firebase cloud messaging
因此,当我去找 firebase 顾问并发送测试通知消息时,应用程序刚刚关闭或可能会崩溃,但没有发生任何事情,我添加了 firebase-analytics
以帮助我调试问题所在以及我得到的结果当我发送测试通知消息时:
Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzq;
at com.google.android.gms.gcm.GcmReceiver.onReceive()
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3177)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1653)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
这是我的代码:
import React from 'react'
import { Platform,View } from 'react-native'
import { Notifications } from 'react-native-notifications'
export default class Pushnotificationmanager extends React.Component {
componentDidMount() {
this.registerDevice()
this.registerNotificationEvents()
}
registerDevice = () => {
Notifications.events().registerRemoteNotificationsRegistered(event => {
// Todo: Send the token to my server so it Could send back push notifications...
console.log('Device Token Received',event.devicetoken)
})
Notifications.events().registerRemoteNotificationsRegistrationFailed(event => {
console.error(event)
})
Notifications.registerRemoteNotifications()
}
registerNotificationEvents = () => {
Notifications.events().registerNotificationReceivedForeground((notification,completion) => {
console.log('Notification Received - Foreground',notification)
})
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
completion({ alert: false,sound: false,badge: false })
})
Notifications.events().registerNotificationopened((notification,completion) => {
console.log('Notification opened by device user',notification)
console.log(`Notification opened with an action identifier: ${notification.identifier}`)
completion()
})
Notifications.events().registerNotificationReceivedBackground((notification,completion) => {
console.log('Notification Received - Background',notification)
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
completion({ alert: true,sound: true,badge: false })
})
Notifications.getinitialNotification()
.then(notification => {
console.log('Initial notification was:',notification || 'N/A')
})
.catch(err => console.error('getinitialNotifiation() Failed',err))
}
render() {
const { children } = this.props
return <View style={{ flex: 1 }}>{children}</View>
}
}
在 console.log
中它安慰令牌并在
Notifications.getinitialNotification()
.then(notification => {
console.log('Initial notification was:',notification || 'N/A')
})
它一直在安慰'N/A'
我用整个应用程序根包裹了之前的代码:
<PaperProvider theme={theme}>
<AuthContext.Provider value={authContext}>
/* here*/ <Pushnotificationmanager>
<NavigationContainer theme={theme}>
<RootStackScreen />
</NavigationContainer>
/* here*/ </Pushnotificationmanager>
</AuthContext.Provider>
</PaperProvider>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。