Created
March 23, 2017 04:11
-
-
Save tjkang/0f3396f06f8727bde7a04bb25b41663e to your computer and use it in GitHub Desktop.
subscribe and unsubscribe to topic for push notification
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
import React, { Component } from 'react'; | |
import { View, StyleSheet, Text } from 'react-native'; | |
import { Actions } from 'react-native-router-flux'; | |
import FCM from 'react-native-fcm'; | |
..... | |
_onLoginSuccess = () => { | |
const topic = '/topics/list' | |
FCM.subscribeToTopic(topic); // subscribe to topic | |
Actions.main(); | |
} | |
_onLoginPress = () => { | |
const { email, password } = this.state; | |
this.setState({ | |
error: '', | |
loading: true, | |
}); | |
firebase.auth().signInWithEmailAndPassword(email, password) | |
.then(this._onLoginSuccess) | |
.catch(error => this._onLoginFailure(error)); | |
} | |
..... |
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
import React, { Component } from 'react'; | |
import { View, StyleSheet, Text } from 'react-native'; | |
import { Actions } from 'react-native-router-flux'; | |
import FCM from 'react-native-fcm'; | |
..... | |
_onLogoutPress = () => { | |
const topic = '/topics/list' | |
FCM.unsubscribeFromTopic(userTopic); // unsubscribe to topic | |
const ref = firebase.database().ref('subjects'); | |
ref.off(); | |
firebase.auth().signOut(); | |
Actions.auth(); | |
}; | |
..... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment