Last active
November 7, 2018 16:00
-
-
Save olegkalyta/01623645b3bc8fdf97fb77eefca51a72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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