xpush-chat client for React Native
##About XPUSH
% npm i https://github.com/xpush/lib-xpush-react-native.git
Tested in React-Native 0.40
- Open up your project in xcode and right click the package.
- Click New Group and rename it
XPush
- Right click in
XPush
folder - Click Add files to 'Your project name'
- Navigate to /node_modules/react-native-xpush-client/ios/XPush/
- Drag all files in
XPush
folder - Click 'Add'
- Then you will see a popup like this, click Create Brdiging Header
- Click your project in the navigator on the left and go to build settings
- Search for swift in
Build Settings
- Double click on Objective-C Bridging Header column
- Enter ../node_modules/react-native-xpush-client/ios/XPush/XPushBridge.h
If you can't find Objective-C Bridging Header option in Build Settings, follow just below
- Create a new file
YourAppName.swift
orYourModuleName.swift
in YourAppName folder - Then you will see a popup like this, click Create Brdiging Header
- Finally search and modify Objective-C Bridging Header option to ../node_modules/react-native-xpush-client/ios/XPush/XPushBridge.h
- add the following import to
MainActivity.java
of your application
import com.facebook.react.shell.MainReactPackage;
- add the following code to add the package to
MainActivity.java
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new XPushPackage() //this
);
}
- add the following codes to your
android/setting.gradle
you might have multiple 3rd party libraries, make sure that you don't create multiple include.
include ':app', ':xpush-client'
project(':xpush-client').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-xpush-client/android/lib')
- edit
android/app/build.gradle
and add the following line insidedependencies
compile project(':react-native-xpush-client')
- run
react-native run-android
to see if everything is compilable.
var XPush = require( 'react-native-xpush-client' );
// setting for xpush server
XPush.init( 'http://54.178.160.166:8000', 'yourAppId', userId, deviceId );
// connect to the `channel01`
XPush.connect( 'channel01', function(err, data){
XPush.onMessage( function( data ){
// handle message
console.log( data );
});
// send message after channel connect
XPush.send( 'hello' );
});