Last active
June 7, 2018 15:01
-
-
Save paulallies/997da4ef631f58c320c6ed2e27fb8a5d to your computer and use it in GitHub Desktop.
myfcmapp App.js
This file contains hidden or 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
/** | |
* Sample React Native App | |
* https://github.com/facebook/react-native | |
* @flow | |
*/ | |
import React, { Component } from 'react'; | |
import { | |
Platform, | |
StyleSheet, | |
Text, | |
View | |
} from 'react-native'; | |
import firebase from 'react-native-firebase'; | |
const instructions = Platform.select({ | |
ios: 'Press Cmd+R to reload,\n' + | |
'Cmd+D or shake for dev menu', | |
android: 'Double tap R on your keyboard to reload,\n' + | |
'Shake or press menu button for dev menu', | |
}); | |
type Props = {}; | |
export default class App extends Component<Props> { | |
/*Add this Block (BEGIN) */ | |
componentDidMount() { | |
firebase.messaging().hasPermission() | |
.then(enabled => { | |
if (enabled) { | |
firebase.messaging().getToken().then(token => { | |
console.log("LOG: ", token); | |
}) | |
// user has permissions | |
} else { | |
firebase.messaging().requestPermission() | |
.then(() => { | |
alert("User Now Has Permission") | |
}) | |
.catch(error => { | |
alert("Error", error) | |
// User has rejected permissions | |
}); | |
} | |
}); | |
} | |
/*Add this Block (END) */ | |
render() { | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.welcome}> | |
Welcome to React Native! | |
</Text> | |
<Text style={styles.instructions}> | |
To get started, edit App.js | |
</Text> | |
<Text style={styles.instructions}> | |
{instructions} | |
</Text> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
backgroundColor: '#F5FCFF', | |
}, | |
welcome: { | |
fontSize: 20, | |
textAlign: 'center', | |
margin: 10, | |
}, | |
instructions: { | |
textAlign: 'center', | |
color: '#333333', | |
marginBottom: 5, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment