React Native Expo - android 的推送通知

问题描述

我正在尝试使用 expo 推送通知工具向 android 设备发送推送通知,(它适用于 iOS)但它不起作用,我添加一个带有单独的 android 应用程序的 firebase 项目,google-service .json,并运行 expo push:android:upload --api-key 。有什么遗漏吗?

我使用的是托管工作流程 SDK 39

这是我使用过的代码,它非常适合 iOS

获取展会推送通知代码

async function registerForPushNotificationsAsync() {
  let token;
  if (Constants.isDevice) {
    const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
    let finalStatus = existingStatus;
    if (existingStatus !== 'granted') {
      const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
      finalStatus = status;
    }
    if (finalStatus !== 'granted') {
      
      return;
    }
    token = (await Notifications.getExpoPushTokenAsync()).data;
    let uid;
    firebase.auth().signInAnonymously()
      .then(() => {
        uid = firebase.auth().currentUser.uid;
      })
      .then(() => {
        db.collection('users').doc(uid).get()
            .then(function(doc) {
                if (doc.exists) {
                    db.collection('users').doc(uid).update({
                      expoPushToken: token,'last use date': new Date().toISOString().slice(0,10),'region': Localization.region
                    })
                } else {
                    db.collection('users').doc(uid).set({
                      expoPushToken: token,'region': Localization.region
                    })
                }
            })
      })
      .catch(() => console.log('ERROR'))

  } else {
    alert('Must use physical device for Push Notifications');
  }

  if (Platform.OS === 'android') {
    Notifications.setNotificationChannelAsync('default',{
      name: 'default',importance: Notifications.AndroidImportance.MAX,vibrationPattern: [0,250,250],lightColor: '#FF231F7C',});
  }

  return token;
}

app.json

"android": {
      "useNextNotificationsApi": true,"googleServicesFile": "./google-services.json","adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png","backgroundColor": "#FFFFFF"
      },"package": "com.NAME.NAME","versionCode": 3
    },

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

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