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:
parent
e438954938
commit
ab2113c324
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue