#RC MOBILE BASE
It is a package that provides shared functionality for all Roomchecking mobile apps.
##Installation
- Add to package.json
"rc-mobile-base": "git+ssh://git@github.com/opula/rc-mobile-base.git",
npm i
oryarn
##Native packages
###Installation
- Please prefer manuall installation for now.
- Please make all APN and GCM specific actions before use RNPusher. Find more info here (https://pusher.com/docs/push_notifications/android/gcm) and (https://pusher.com/docs/push_notifications/ios/apns)
####iOS
#####Automatically
- Run
react-native link rc-mobile-base
#####Manually
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜rc-mobile-base
and addRNPusher.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNPusher.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Click
RNPusher.xcodeproj
in the project navigator and go theBuild Settings
tab. Make sure 'All' is toggled on (instead of 'Basic'). Look forHeader Search Paths
and make sure it contains$(SRCROOT)/../react-native/React
,$(SRCROOT)/../../React
,${SRCROOT}/../../ios/Pods/Headers/Public
and${SRCROOT}/../../ios/Pods/Headers/Public/libPusher
- all marked asrecursive
. - Inside your
ios
directory add a file namedPodfile
- Add
pod 'libPusher', git: 'https://github.com/pusher/libPusher.git', branch: 'push-notifications'
and specify your target (your xcode project name) - Install
PushNotificationIOS
as described here - Run
pod install --project-directory=ios
- Run
react-native run-ios
If you used to run project with react-native run-ios
, please change Build Configuration
to Debug
under Run
tab in project's scheme editor.
####Android
#####Automatically
- Run
react-native link rc-mobile-base
- Change
AndroidManifest.xml
same as while manual installation.
#####Manual
In your file android/settings.gradle
add the following
include ':rc-mobile-base'
project(':rc-mobile-base').projectDir = new File(rootProject.projectDir, '../node_modules/rc-mobile-base/android')
In the file android/app/build.gradle
add a new dependency
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.pusher:pusher-websocket-android:0.3.1'
compile project(':rc-mobile-base')
}
And in the same file inside the android:defaultConfig
section
multiDexEnabled true
And at the bottom of the file
apply plugin: 'com.google.gms.google-services'
Don't forget to set
minSdkVersion 23
targetSdkVersion 23
as it is required by native pusher lib.
In the file android/build.gradle
add a new classpath dependency
classpath 'com.google.gms:google-services:3.0.0'
And new repository
maven { url 'http://clojars.org/repo' }
Then in the file MainApplication.java
add the following Java imports
import android.content.Context;
import android.support.multidex.MultiDex;
import com.rcmobilebase.rnpusher.RNPusher;
and add Native module
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
//Other RN modules
new RNPusher()
);
}
and also add multidex support
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Then in your android/app/src/main/AndroidManifest.xml
add the following inside <application>
tag
<!-- Pusher's GCM listeners and services -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="gcm.play.android.samples.com.gcmquickstart" />
</intent-filter>
</receiver>
<service
android:name="com.pusher.android.notifications.gcm.PusherGCMListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="com.pusher.android.notifications.gcm.GCMInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name="com.pusher.android.notifications.gcm.GCMRegistrationIntentService"
android:exported="false">
</service>
Then copy your google-services.json
file to android/app
.
And finally run react-native run-android
.
###Usage
- Required package
import nativePusher from 'rc-mobile-base/react-native-pusher';
- Define pusher api key and gcm sender id (which is your project number)
const pusherKey = '02750edc36b43c0110a3';
const senderId = '912214320959';
- Init native pusher
const pusherPN = nativePusher({ deviceId: senderId, pusherKey });
- Register your client and subscribe to some interest
this.pusherPN.register();
this.pusherPN.subscribe('roomcheckingsystem');
- You have to unregister your instance when app has done it's job
this.pusherPN.unregister();
this.pusherPN.unsubscribe('roomcheckingsystem');
Please reference runner for more detailed example.