我正在使用react-native开发一个Android应用程序,我想使用本地推送通知,就像我点击按钮时,推送通知应该创建 . 我怎样才能做到这一点?有人请给我一些建议 .
您可以尝试使用 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
<Button title="title of button" onPress ={this.scheduleNotfication() } > <Text>show</Text> </Button>
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);
这是完美的,并在一定时间内获得本地推送通知 .
你也可以试试
react-native-notifications
它可以帮助您进行本地以及远程推送通知 .
1.Remote(推送)通知
2.本地通知
3.Background /托管通知(可以从服务器清除的通知,如Facebook Messenger和Whatsapp网站)
4.PushKit API(用于VoIP和其他背景消息)
5.Interactive通知(允许您为应用程序之外的用户提供其他功能,例如操作按钮)
代码片段 - >
import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, Button, TouchableHighlight } from 'react-native'; import {NotificationsAndroid} from 'react-native-notifications'; export default class pushLocalNotification extends Component { get_Local_Notfication() { NotificationsAndroid.localNotification({ title: "Local notification", body: "This notification was generated by the app!", extra: "data" }); } render() { return ( <View> <TouchableHighlight onPress = {this.get_Local_Notfication.bind(this) } > <Text>show</Text> </TouchableHighlight> </View> ); } } AppRegistry.registerComponent('pushLocalNotification', () => pushLocalNotification);
这对我来说非常合适 .
3 回答
您可以尝试使用 react-native-push-notification
Button
这是完美的,并在一定时间内获得本地推送通知 .
你也可以试试
react-native-notifications
它可以帮助您进行本地以及远程推送通知 .
1.Remote(推送)通知
2.本地通知
3.Background /托管通知(可以从服务器清除的通知,如Facebook Messenger和Whatsapp网站)
4.PushKit API(用于VoIP和其他背景消息)
5.Interactive通知(允许您为应用程序之外的用户提供其他功能,例如操作按钮)
代码片段 - >
这对我来说非常合适 .