Skip to content

Instantly share code, notes, and snippets.

@olegkalyta
Last active November 7, 2018 16:00
Show Gist options
  • Save olegkalyta/01623645b3bc8fdf97fb77eefca51a72 to your computer and use it in GitHub Desktop.
Save olegkalyta/01623645b3bc8fdf97fb77eefca51a72 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import { PushNotificationIOS, Alert } from 'react-native'
class PushNotificationHandler extends Component {
componentDidMount() {
console.log('component did mount')
PushNotificationIOS.addEventListener('register', token => {
console.log(token)
Alert.alert(token)
})
PushNotificationIOS.addEventListener('registrationError', registrationError => {
console.log(registrationError, '--')
})
PushNotificationIOS.addEventListener('notification', function(notification) {
if (!notification) {
return
}
const data = notification.getData()
Alert.alert(JSON.stringify({ data, source: 'CollapsedApp' }))
})
PushNotificationIOS.getInitialNotification().then(notification => {
if (!notification) {
return
}
const data = notification.getData()
Alert.alert(JSON.stringify({ data, source: 'ClosedApp' }))
})
PushNotificationIOS.requestPermissions()
}
render() {
return null
}
}
export default PushNotificationHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment