Reputation: 347
I am developing an android app using react-native, i want to use local push notification for that, like whenever i click on button, push notification should create. how can i do this? someone please suggest me something.
Upvotes: 2
Views: 1937
Reputation: 727
You can also try
It helps you in local as well as a remote push notification.
1.Remote (push) notifications
2.Local notifications
3.Background/Managed notifications (notifications that can be cleared from the server, like Facebook messenger and Whatsapp web)
4.PushKit API (for VoIP and other background messages)
5.Interactive notifications (allows you to provide additional functionality to your users outside of your application such as action buttons)
Code snippets -->
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);
This is working perfectly for me.
Upvotes: 0
Reputation: 347
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);
This is working perfect and getting local Push Notification for certain time.
Upvotes: 1
Reputation: 1889
You could try this with 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>
Upvotes: 1