收到通知时 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...