【问题标题】:Exception occurred while executing exported method getDevicePushTokenAsync on module ExpoPushTokenManager在模块 ExpoPushTokenManager 上执行导出方法 getDevicePushTokenAsync 时发生异常
【发布时间】:2020-12-21 16:02:51
【问题描述】:

我升级了我的世博会推送通知,每当我在 Android 上运行它时,都会收到以下错误:

执行导出方法时发生异常 模块 ExpoPushTokenManager 上的 getDevicePushTokenAsync。请设置 您的项目 ID。需要有效的 Firebase 项目 ID 与 Firebase 服务器 API 通信:它将您的项目标识为 古尔格。

谁能告诉我应该把项目 ID 放在哪里?我在我的config.js 文件中将它链接到我的项目中,但我觉得它也应该在我的app.json 文件中,只是不能100% 确定在哪里。

{
  "expo": {
    "name": "Galavant",
    "slug": "Galavant",
    "platforms": ["ios", "android", "web"],
    "version": "2.0.8",
    "orientation": "portrait",
    "icon": "./assets/logo.png",
    "splash": {
      "image": "./assets/logo_original.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "usesAppleSignIn": true,
      "infoPlist": {
        "NSCameraUsageDescription": "So you can add photos to your profile.",
        "NSPhotoLibraryUsageDescription": "So you can add photos to your profile.",
        "NSLocationWhenInUseUsageDescription": "So you can connect with people nearby."
      },
      "supportsTablet": true,
      "bundleIdentifier": "com.test.test",
      "buildNumber": "0.0.1",
      "config": {
        "googleSignIn": {
          "reservedClientId": "com.googleusercontent.apps.12346789"
        }
      }
    },
    "android": {
      "package": "com.test.test",
      "useNextNotificationsApi": true,
      "versionCode": 5,
      "config": {
        "googleMaps": {
          "apiKey": "asdkjfkasjdf9837983rlkajshf"
        },
        "googleSignIn": {
          "apiKey": "asdkjfkasjdf9837983rlkajshf", 
          "certificateHash": "33345w4sdfasdkjfkasjdf9837983srlkajshf"
        }
      },
      "permissions": [
        "ACCESS_COARSE_LOCATION",
        "ACCESS_FINE_LOCATION",
        "CAMERA",
        "MANAGE_DOCUMENTS",
        "READ_CONTACTS",
        "READ_CALENDAR",
        "WRITE_CALENDAR",
        "READ_EXTERNAL_STORAGE",
        "READ_PHONE_STATE",
        "RECORD_AUDIO",
        "USE_FINGERPRINT",
        "VIBRATE",
        "WAKE_LOCK",
        "WRITE_EXTERNAL_STORAGE",
        "com.anddoes.launcher.permission.UPDATE_COUNT",
        "com.android.launcher.permission.INSTALL_SHORTCUT",
        "com.google.android.c2dm.permission.RECEIVE",
        "com.google.android.gms.permission.ACTIVITY_RECOGNITION",
        "com.google.android.providers.gsf.permission.READ_GSERVICES",
        "com.htc.launcher.permission.READ_SETTINGS",
        "com.htc.launcher.permission.UPDATE_SHORTCUT",
        "com.majeur.launcher.permission.UPDATE_BADGE",
        "com.sec.android.provider.badge.permission.READ",
        "com.sec.android.provider.badge.permission.WRITE",
        "com.sonyericsson.home.permission.BROADCAST_BADGE"
      ]
    },
    "notification": {
      "icon": "./assets/PushNotification.png"
    }
  }
}

【问题讨论】:

  • 我也有同样的问题,你解决了吗?
  • @MehmetYenerYılmaz 我做到了,我刚刚添加了我的解决方案。希望对您有所帮助!

标签: firebase react-native expo android-push-notification react-native-push-notification


【解决方案1】:

我最终做了一些事情。首先,我创建并添加了google-services.json 文件。我在"web" 部分添加了项目ID,最后我用useNextNotificationsApi 更新了“android”部分

"android": {
  "package": "com.test.test",
  "googleServicesFile": "./google-services.json",
  "useNextNotificationsApi": true,
  "versionCode": 10,
  "config": {
    "googleMaps": {
      "apiKey": "123456789"
    },
    "googleSignIn": {
      "apiKey": "123456789",
      "certificateHash": "123456789asdfasdf"
    }
  },
  "permissions": [
    "ACCESS_COARSE_LOCATION",
    "ACCESS_FINE_LOCATION",
    "CAMERA",
    "USE_FINGERPRINT",
    "VIBRATE"
  ]
},
"web": {
  "config": {
    "firebase": {
      "projectId": "testprojectID",
      "apiKey": "123456789",
      "measurementId": "measurementid123"
    }
  }
},

【讨论】:

    【解决方案2】:

    我尝试切换到托管流以尝试处理后台通知(这在 Expo Go 中不起作用)并得到完全相同的错误(在提及 projectId 时获取 Expo 推送令牌时无法启动)。

    我最终确实让我的工作了。如果它对其他人有帮助,这就是我偶然发现的地方......

    首先,我确认我有这两个键:

      "googleServicesFile": "./google-services.json",
      "useNextNotificationsApi": true,
    

    其次,我认为我没有完全正确地遍历所有https://docs.expo.dev/push-notifications/using-fcm/。我让整个“客户端设置”正常工作,但后来忘记了“上传服务器凭据”。

    第三,可能也是最令人困惑的,我也是发布和更新的新手。我在我的应用程序上创建了一个调试页面,显示了它从 Play 商店运行的版本(至少我认为是这样)。但它只会在我将 Play 应用程序发布到内部测试后打开然后关闭并重新打开它时才会更新......在了解了有关 OTA 更新的更多信息后,我意识到这实际上是正在发生的事情,而我实际上并没有得到即使我的 Constants.manifest.android.versionCode 和应用程序版本出现更新(因为它们以某种方式通过 OTA 交付..),但设置了新的 android 密钥的最新版本。

    所以最后解决我的问题是通过 Play 手动卸载我的内部测试应用程序,然后从头开始重新安装!

    【讨论】:

    • 这行得通吗?
    • 它对我有用。但正如您从我的文字中可以看出的那样,有许多问题同时发生,因此您的结果可能会有所不同。
    猜你喜欢
    • 1970-01-01
    • 2011-08-23
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多