Package Exports
- pushbots-react-native
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pushbots-react-native) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
pushbots-react-native
React Native Library for PushBots Push Notifications Service
Getting started
npm install pushbots-react-native --save
Automatic Installation
react-native link pushbots-react-native
Configuration
iOS
Add Required Capabilities
- Select the root project and then under Capabilities click to enable "Push Notifications".
- Enable "Background Modes" and check "Remote notifications".
Adding the Code
in
AppDelegate.m
:On the
application didFinishLaunchingWithOptions
method, add the following code (replace APP_ID with your PushBots app ID):Add this line to didFinishLaunchingWithOptions:
self.PushbotsClient = [[RCTPushbots alloc] initWithAppId:@"APP_ID"];
- Voila!
Android
Go to build.gradle
app level and add this in default config
Add the following to defaultConfig in build.gradle
file inside the android/app folder
defaultConfig {
manifestPlaceholders = [
pushbots_app_id: "APP_ID",
google_sender_id: "SENDER_ID",
pushbots_loglevel: "DEBUG"
]
}
Usage
in your App.js:
import Pushbots from 'pushbots-react-native'
Pushbots.registerForRemoteNotifications()
//events work with iOS only in this version.
export default class App extends Component<{}> {
componentWillMount() {
console.log("Adding listener");
Pushbots.addEventListener('received', this.onReceived);
}
componentWillUnmount() {
Pushbots.removeEventListener('received', this.onReceived);
}
onReceived(notification) {
Alert.alert( 'Alert Title', JSON.stringify(notification), [ {text: 'Ask me later', onPress: () => console.log('Ask me later pressed')}, {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}, {text: 'OK', onPress: () => console.log('OK Pressed')}, ], { cancelable: false } )
}
}
Contributors
Thanks goes to these wonderful people:
Mohamed Shaban 💻 |
Abdullah Diaa 💻 |
meMuhammadkamal 💻 |
amrsobhy 📖 |
---|
Contributions of any kind welcome!