Update PushNotificationIOS documentation

Summary:* add sample for localNotification listener
Closes https://github.com/facebook/react-native/pull/7114

Differential Revision: D3212587

Pulled By: mkonicek

fb-gh-sync-id: 1251a5563cf4254c4de491d45aafe8d1c24aeb0f
fbshipit-source-id: 1251a5563cf4254c4de491d45aafe8d1c24aeb0f
This commit is contained in:
Tanguy Antoine 2016-04-22 09:15:37 -07:00 committed by Facebook Github Bot 4
parent e438954938
commit ab2113c324
1 changed files with 34 additions and 1 deletions

View File

@ -43,11 +43,17 @@ var Button = React.createClass({
class NotificationExample extends React.Component {
componentWillMount() {
// Add listener for push notifications
PushNotificationIOS.addEventListener('notification', this._onNotification);
// Add listener for local notifications
PushNotificationIOS.addEventListener('localNotification', this._onLocalNotification);
}
componentWillUnmount() {
// Remove listener for push notifications
PushNotificationIOS.removeEventListener('notification', this._onNotification);
// Remove listener for local notifications
PushNotificationIOS.removeEventListener('localNotification', this._onLocalNotification);
}
render() {
@ -57,6 +63,11 @@ class NotificationExample extends React.Component {
onPress={this._sendNotification}
label="Send fake notification"
/>
<Button
onPress={this._sendLocalNotification}
label="Send fake local notification"
/>
</View>
);
}
@ -72,9 +83,31 @@ class NotificationExample extends React.Component {
});
}
_sendLocalNotification() {
require('RCTDeviceEventEmitter').emit('localNotificationReceived', {
aps: {
alert: 'Sample local notification',
badge: '+1',
sound: 'default',
category: 'REACT_NATIVE'
},
});
}
_onNotification(notification) {
AlertIOS.alert(
'Notification Received',
'Push Notification Received',
'Alert message: ' + notification.getMessage(),
[{
text: 'Dismiss',
onPress: null,
}]
);
}
_onLocalNotification(notification){
AlertIOS.alert(
'Local Notification Received',
'Alert message: ' + notification.getMessage(),
[{
text: 'Dismiss',