| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
React-Native sample using SendBird SDK. Redux pattern is applied to the project.
Make sure that you have installed Node.js 6.x or above.
Install React Native CLI (if not installed)
npm install -g react-native-cli
Install package
npm install
Start sample.
react-native run-android react-native run-ios
A. This sample uses react-native-push-notification for push notification. You can follow the instructions in the github page so as to setup for Android and iOS. Then SendBird SDK requires more treaks on the code to handle the push notification properly.
import { AppState } from 'react-native';
/// abbrev.
const sb = new SendBird({ 'appId': YOUR_APP_ID }); // or SendBird.getInstance() if SendBird is already initialized
class App extends Component {
_handleAppStateChange = (currentAppState) => {
if (currentAppState === 'active') {
if(sb) {
sb.setForegroundState();
}
} else if (currentAppState === 'background') {
if(sb) {
sb.setBackgroundState();
}
}
}
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}
render() {
return ...
}
}import { Platform } from 'react-native';
/// abbrev.
const sb = new SendBird({ 'appId': YOUR_APP_ID }); // or SendBird.getInstance() if SendBird is already initialized
PushNotification.configure({
onRegister: function(token) {
if (Platform.OS === 'ios') {
sb.registerAPNSPushTokenForCurrentUser(token['token'], function(result, error) {
});
} else {
sb.registerGCMPushTokenForCurrentUser(token['token'], function(result, error) {
});
}
},
onNotification: function(notification) {
// TODO: put some code to handle notification data
console.log(notification);
},
...A. Check that the app is foreground or alive in background. GCM doesn't show notification when the app is in activated state. If it's not the case, check that you have multiple devices for the same user account. GCM notification arrives only at one device for a single device token.
| Back | FazBrowse Home | New Git URL |