ios - 使用 React Native 的 iOS 后台通知
问题描述
我是原生反应新手,我正在尝试创建一个应用程序,允许用户收听每周通过数据库发布的播客。每次发布新播客时,我都希望用户收到后台通知。
我已经做了一些研究,并且能够对打开应用程序时显示的本地通知做出反应(如下所示) 我一直在关注本教程
https://wix.github.io/react-native-notifications/docs/localNotifications
这是我的代码
import React from 'react';
import {View} from 'react-native';
import {Notifications} from 'react-native-notifications';
import HomeStack from './app/nav';
export default class App extends React.Component {
constructor(props) {
super(props);
Notifications.registerRemoteNotifications();
Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion) => {
console.log(`Notification received in foreground: ${notification.title} : ${notification.body}`);
completion({alert: true, sound: false, badge: true});
});
Notifications.events().registerNotificationOpened((notification: Notification, completion) => {
console.log(`Notification opened: ${notification.payload}`);
completion();
});
}
someLocalNotification = Notifications.postLocalNotification({
body: 'Local notification!',
title: 'Local Notification!',
//sound: "chime.aiff",
category: 'SOME_CATEGORY',
userInfo: {},
});
render() {
return <View style={{ flex: 1 }}><HomeStack /></View>
}
}
在做了一些研究之后,我发现一些教程有点令人困惑或不起作用。我想知道创建后台通知的最佳方法是什么?
解决方案
你需要在你的项目中集成firebase,我也面临这个问题,firebase集成是解决方案,在应用程序打开或关闭时获取动态通知内容。npm i react-native-firebase
推荐阅读
- c++ - POSIX C/C++ 日志文件(VEX V5 大脑)
- microsoft-translator - XHTML 修改不正确
- c++ - Pybind11 + nan Node 模块冲突
- task - 赛普拉斯任务。然后不按预期工作
- python - 我不断收到 500 内部服务器错误
- amazon-web-services - scheduling notebooks within EMR and issue installing libraries aws
- r - How to plot maps scattered over another plot (i.e. outside their actual coordinates)?
- javascript - 有没有办法在屏幕调整大小时关闭导航下拉菜单?
- java - 如何将文本文件的行读入JavaFx中的数组
- tfs - 贡献者签入后管理员验证代码 - TFS