请检查此处提出的问题以获取更多信息,因为我想在 Expo React Native 中准确实现这一点
我尝试过使用 expo-notification 包和 Notifee 包,但似乎找不到添加此功能的方法
这可以使用 Notifee/react-native 包来实现,它适用于 bare expo 和 React Native cli 项目,对于安装 notifee 后的裸 expo 项目,请遵循其文档here,然后通过应用程序将所需的功能添加到应用程序.json 文件由
"ios": {
"entitlements": {
"com.apple.developer.usernotifications.communication": true
},
"infoPlist": {
"UIBackgroundModes": ["location", "fetch", "remote-notification"],
"NSUserActivityTypes": ["INSendMessageIntent"]
},
}
这为 ios 添加了通信通知功能,并将 INSendMessageIntent 添加到 info.plist 中的 NSUserActivityTypes
然后使用 Notifee 包通过以下方式显示通知:
await notifee.displayNotification({
title: "Some title",
body: "Notification Body",
ios: {
foregroundPresentationOptions: {
badge: true,
sound: true,
banner: true,
list: true,
},
categoryId: 'messageID',
communicationInfo: {
conversationId: "123",
sender: {
id: "456",
avatar: "Avatar-url",
displayName: "John Doe",
},
},
}
})