### Config for notification and `click_action` in Android
To allow android to respond to `click_action`, you need to define Activities and filter on specific intent. Since all javascript is running in MainActivity, you can have MainActivity to handle actions.
```xml
<activity
To allow android to respond to `click_action`, you need to define Activities and filter on specific intent. Since all javascript is running in MainActivity, you can have MainActivity to handle actions:
In [firebase console](https://console.firebase.google.com/), you can get `google-services.json` file and place it in `android/app` directory and get `GoogleService-Info.plist` file and place it in `/ios/your-project-name` directory (next to your `Info.plist`)
## Usage
```javascript
importFCMfrom'react-native-fcm';
importFCMfrom'react-native-fcm';
...
componentWillMount(){
FCM.requestPermissions();
classAppextendsComponent{
componentDidMount(){
FCM.requestPermissions();// for iOS
FCM.getFCMToken().then(token=>{
console.log(token)
// store fcm token in your server
...
...
@@ -140,11 +172,11 @@ In [firebase console](https://console.firebase.google.com/), you can get `google
}
componentWillUnmount(){
// prevent leak
// prevent leaking
this.refreshUnsubscribe();
this.notificationUnsubscribe();
}
...
}
```
### Behaviour when sending `notification` and `data` payload through GCM
...
...
@@ -159,8 +191,9 @@ In [firebase console](https://console.firebase.google.com/), you can get `google
* if you pass `notification` payload. it will receive data when user click on notification
* if you pass `data` payload only, it will receive data when in background
e.g. fcm payload looks like
```
e.g. fcm payload looks like:
```json
{
"to":"some_device_token",
"content_available":true,
...
...
@@ -174,34 +207,51 @@ In [firebase console](https://console.firebase.google.com/), you can get `google
}
}
```
and event callback will receive as
```
///Android
and event callback will receive as:
- Android
```json
{
fcm: {"action": "fcm.ACTION.HELLO"},
extra: "juice"
"fcm": {"action": "fcm.ACTION.HELLO"},
"extra": "juice"
}
///IOS
```
- iOS
```json
{
apns: {action_category: "fcm.ACTION.HELLO"},
extra: "juice"
"apns": {"action_category": "fcm.ACTION.HELLO"},
"extra": "juice"
}
```
- When app is running in foreground
- IOS will receive notification and android **won't** (better not to do anything in foreground for hybrid and send a seprate data message.)
NOTE: it is recommend not to rely on `data` payload for click_action as it can be overwritten. check [this](http://stackoverflow.com/questions/33738848/handle-multiple-notifications-with-gcm)
NOTE: it is recommend not to rely on `data` payload for click_action as it can be overwritten (check [this](http://stackoverflow.com/questions/33738848/handle-multiple-notifications-with-gcm)).
## Q & A
#### My android build is failing
#### My Android build is failing
Try update your SDK and google play service
#### I can't get notification when app is killed
If you send notification with `data` only, you can only get the data message when app is in foreground or background. Killed app doesn't trigger FCMNotificationReceived. Use `notification` in the payload instead
If you send notification with `data` only, you can only get the data message when app is in foreground or background. Killed app doesn't trigger `FCMNotificationReceived`. Use `notification` in the payload instead.
#### App running in background doesn't trigger `FCMNotificationReceived` when receiving hybrid notification [Android]
These is [an issue opened for that](https://github.com/google/gcm/issues/63). Behavior is not consistent between 2 platforms
#### Android notification is showing a white icon
Since Lolipop, push notification icon is required to be all white, otherwise it will be a white circle.
#### It is missing some features
Issues and pull requests are welcomed. Let's make this thing better!
Since Lollipop, the push notification icon is required to be all white, otherwise it will be a white circle.
#### I am using Proguard
You need to add this to your `android/app/proguard-rules.pro`:
```
# Google Play Services
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
```
#### Some features are missing
Issues and pull requests are welcome. Let's make this thing better!