我正在使用以下代码在 Android 上为我的 expo react 应用程序创建两个通道:
Notifications.setNotificationChannelAsync("default", {
name: "default",
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: "#FF231F7C",
})
Notifications.setNotificationChannelAsync("gameupdates", {
name: "gameupdates",
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: "#FF231F7C",
})
Run Code Online (Sandbox Code Playgroud)
频道已成功创建,当我进入 Expo 应用程序通知选项时,我什至可以找到它。
当我使用没有任何频道 ID 的expo 工具发送通知时,它工作正常。但是,当我使用频道 ID“gameupdates”时,通知永远不会到达我的手机。
知道为什么吗?
我在博览会 sdk 38 上。
我在项目中使用 expo React Native,并且在项目中使用 expo-notifications 包。
我已将 "useNextNotificationsApi": true 添加到 android 对象下的 app.json 文件中,该文件位于 expo 对象下,因此 expo.android.useNextNotificationsApi : true。
我还在从服务器发送到 expo 服务器的消息上设置了 experienceId,我使用https://github.com/expo/expo-server-sdk-node包进行发送。
messages.push({
to: red_user.fcm_token,
sound: 'default',
title: "Stylist Response",
body: "Stylist has agreed to fulfill the request",
data: {
experienceId: "@glamcentralng/GlamCentral",
order: order._id,
stylist_response: "agreed"
},
})
Run Code Online (Sandbox Code Playgroud)
在我的 expo React Native 应用程序中,我正在使用我提到的 expo-notifications 包,并且我的类组件中有以下设置。
import * as Notifications from 'expo-notifications';
.
.
.
.
componentDidMount() {
//Not working at all
Notifications.addNotificationReceivedListener( notification => {
console.log(notification);
this._handleNotification(notification) …
Run Code Online (Sandbox Code Playgroud) 我在 React Native (expo) 中使用 expo-notifications 包来处理传入的通知。当应用程序位于后台和前台时,我可以正确收到通知 - 为了发送通知,我在后端使用“expo-server-sdk”包。我可以使用 expo-notification 包中的 addNotificationReceivedListener() 函数处理前台通知接收。用于处理 expo 文档中的后台通知接收(链接:- https://docs.expo.dev/versions/latest/sdk/notifications/#handling -incoming-notifications-when-the-app-is-1)他们说我们可以使用 expo-task-manager 库来处理它。下面给出了我参考博览会文档编写的代码。
...
import * as Notifications from 'expo-notifications';
import * as TaskManager from 'expo-task-manager';
...
//This code is written in root file and outside any react component
const BACKGROUND_NOTIFICATION_TASK = 'BACKGROUND-NOTIFICATION-TASK';
TaskManager.defineTask(
BACKGROUND_NOTIFICATION_TASK,
({ data, error, executionInfo }) =>{
if(error){
console.log('error occurred');
}
if(data){
console.log('data-----',data);
}
})
Run Code Online (Sandbox Code Playgroud)
//This code is written in App.js root component
useEffect(() => {
Notifications.registerTaskAsync(BACKGROUND_NOTIFICATION_TASK);
return()=>{
Notifications.unregisterTaskAsync(BACKGROUND_NOTIFICATION_TASK); …
Run Code Online (Sandbox Code Playgroud) 我想让我的应用程序为推送通知做好准备。因此,我将 Expo Notifications 与 React-Native-Firebase 一起使用(它是一个裸工作流程应用程序)。Mi错误来自Podfile。对于 firebase 我需要添加use_frameworks!
但比我得到这个错误:
node_modules/react-native/React/Base/RCTBridge.m:17:9: fatal error: 'RCTDevLoadingViewProtocol.h' file not found
#import "RCTDevLoadingViewProtocol.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Run Code Online (Sandbox Code Playgroud)
在 Github 上,我发现要修复此错误,我需要删除use_frameworks!
. 但如果我删除它,我会收到以下错误:
ios/Pods/Headers/Public/glog/glog/logging.h:509:1: note: namespace 'google' begins here
namespace google {
^
1 error generated.
Run Code Online (Sandbox Code Playgroud)
有解决方案来解决这个问题吗?这是我的版本:
- "@expo/react-native-action-sheet": "^3.13.0",
- "@fortawesome/free-brands-svg-icons": "^6.1.1",
- "@fortawesome/pro-light-svg-icons": "^6.1.1",
- "@fortawesome/pro-regular-svg-icons": "^6.1.1",
- "@fortawesome/pro-solid-svg-icons": "^6.1.1",
- "@fortawesome/react-native-fontawesome": "^0.2.7",
- "@invertase/react-native-apple-authentication": "^2.2.0",
- "@openspacelabs/react-native-zoomable-view": "^2.0.4",
- "@react-native-community/netinfo": "^8.3.0",
- "@react-native-firebase/app": "^14.11.0",
- "@react-native-google-signin/google-signin": "^7.2.2",
- "@react-navigation/bottom-tabs": "^6.3.1",
- "@react-navigation/stack": "^6.2.1",
- "日期-fns": "^2.28.0",
- "世博会": "~45.0.0",
- "expo-image-picker": "^13.1.1",
- "expo-localization": "^13.0.0",
- "博览会地点": "^14.2.2",
- "expo-notifications": …
我正在创建一个博览会反应本机应用程序,需要能够向用户发送推送通知。由于该应用程序将在 iOS 和 Android 上运行,因此我们计划使用 Expo 的推送通知服务。
但是,每当我尝试使用 时Notifications.getExpoPushTokenAsync()
,都会收到以下错误:
No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself
Run Code Online (Sandbox Code Playgroud)
据我所知,我已经设置了 Firebase 云消息传递和 Apple 推送通知,并将它们链接到https://expo.dev上的我的博览会项目。到目前为止,我只在 iOS 上测试过这一点,所以我不确定它是否也发生在 Android 上。
push-notification apple-push-notifications firebase-cloud-messaging expo expo-notifications