Android 如何使用react本机推送通知创建本地推送通知

Android 如何使用react本机推送通知创建本地推送通知,android,react-native,push-notification,Android,React Native,Push Notification,我正在使用react native开发一个android应用程序,我想使用本地推送通知,就像每当我点击按钮时,推送通知都应该创建。我该怎么做? 有人请给我提些建议 import React,{Component}来自'React'; import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, Button, TouchableHighlight } from

我正在使用react native开发一个android应用程序,我想使用本地推送通知,就像每当我点击按钮时,推送通知都应该创建。我该怎么做? 有人请给我提些建议

import React,{Component}来自'React';
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Button,
 TouchableHighlight
 } from 'react-native';

import PushNotification from 'react-native-push-notification';

export default class pn extends Component {
  scheduleNotfication() { 
PushNotification.localNotificationSchedule({ 
message: "My Notification Message", // message 
date: new Date(Date.now() + (60 * 1000)) // your required time 
}); 
}
  render() {
    return (
      <View>


<TouchableHighlight onPress ={this.scheduleNotfication.bind(this) } >
<Text>show</Text> 
</TouchableHighlight>

      </View>
    );
  }
}


AppRegistry.registerComponent('pn', () => pn);
进口{ 评估学, 样式表, 文本, 看法 按钮 可触摸高光 }从“反应本机”; 从“反应本机推送通知”导入推送通知; 导出默认类pn扩展组件{ ScheduleNotification(){ PushNotification.localNotificationSchedule({ 消息:“我的通知消息”、//消息 日期:新日期(date.now()+(60*1000))//您所需的时间 }); } render(){ 返回( 显示 ); } } AppRegistry.registerComponent('pn',()=>pn);

这是一个完美的工作方式,可以在一定时间内获得本地推送通知。

您可以使用react native Push Notification来尝试这一点。

import PushNotification from 'react-native-push-notification';

scheduleNotfication() { 
 PushNotification.localNotificationSchedule({ 
 message: "My Notification Message", // message 
 date: new Date(Date.now() + (60 * 1000)) // your required time 
 }); 
}  
<Button title="title of button" onPress ={this.scheduleNotfication() } > 
<Text>show</Text> 
</Button>
按钮

import PushNotification from 'react-native-push-notification';

scheduleNotfication() { 
 PushNotification.localNotificationSchedule({ 
 message: "My Notification Message", // message 
 date: new Date(Date.now() + (60 * 1000)) // your required time 
 }); 
}  
<Button title="title of button" onPress ={this.scheduleNotfication() } > 
<Text>show</Text> 
</Button>

显示
您也可以尝试

它可以在本地和远程推送通知中帮助您

1.远程(推送)通知

2.本地通知

3.后台/托管通知(可从服务器上清除的通知,如Facebook messenger和Whatsapp web)

4.PushKit API(用于VoIP和其他后台消息)

5.交互式通知(允许您向应用程序之外的用户提供附加功能,如操作按钮)

代码片段-->

import React,{Component}来自'React';
进口{
评估学,
样式表,
文本,
看法
按钮
可触摸高光
}从“反应本机”;
从“反应本机通知”导入{NotificationsAndroid};
导出默认类pushLocalNotification扩展组件{
获取\u本地\u通知(){
NotificationsAndroid.localNotification({
标题:“本地通知”,
正文:“此通知由应用程序生成!”,
额外:“数据”
});
}
render(){
返回(
显示
);
}
}
AppRegistry.registerComponent('pushLocalNotification',()=>
(本地通知);

这对我来说非常有效。

您可以将或用于本地推送通知和远程通知。谢谢@Hariks,但我不了解如何使用该代码。我应该在哪里调用函数。在“用法”中,他们给出了一些我不理解的代码,在哪里编写代码?反应本机部分或添加包的本机部分?反应本机部分