Git Product home page Git Product logo

react-native-fcm's Introduction

Join the chat at https://gitter.im/evollu/react-native-fcm

Deprecated

I'm not longer able to maintain this repo. check react-native-firebase instead

To existing react-native-fcm users

react-native-firebase now can do what react-native-fcm can so it is a waste of effort to build the same thing in parallel.

Since I'm getting busier these days and start feeling challenging to maintain this repo every day while react-native-firebase has a larger team/company backing it, existing users may consider migrating to react-native-firebase.

I've created an example project using react-native-firebase as a migration reference

react-native-fcm will still take PRs and bug fixes, but possibly no new feature developement any more.

Versions

Example

Installation

Configure Firebase Console

FCM config file

In firebase console, you can:

  • for Android: download google-services.json file and place it in android/app directory.
  • for iOS: download GoogleService-Info.plist file and place it in /ios/your-project-name directory (next to your Info.plist)

Make sure you have certificates setup by following https://firebase.google.com/docs/cloud-messaging/ios/certs


Android Configuration

  • As react-native link sometimes has glitches, make sure you have this line added

Edit android/build.gradle:

NOTE: The followed line may not be up-to-dated. Please refer to https://firebase.google.com/docs/android/setup

buildscript {
    repositories {
        // ...
        google() // Google's Maven repository
    }
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:4.0.2' // google-services plugin
    }
}

allprojects {
    // ...
    repositories {
        // ...
        google() // Google's Maven repository
    }
}

Edit android/app/build.gradle:

NOTE: Please refer to https://firebase.google.com/docs/android/setup

dependencies {
    // ...
    compile project(':react-native-fcm')

    // ...
    
    // Automatically selecting the latest available version
    implementation 'com.google.firebase:firebase-core'
    implementation 'com.google.firebase:firebase-messaging'
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

Edit android/app/src/main/AndroidManifest.xml:

NOTE: The resource @mipmap/ic_notif is referring to android/app/src/res/mipmap-<resolution>/ folder. Feel free to change the filename if you have a customised icon for notification.

  <application
    ...
    android:theme="@style/AppTheme">

+    <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_notif"/>
+    <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="my_default_channel"/>

+   <service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
+     <intent-filter>
+       <action android:name="com.google.firebase.MESSAGING_EVENT"/>
+     </intent-filter>
+   </service>

+   <service android:name="com.evollu.react.fcm.InstanceIdService" android:exported="false">
+     <intent-filter>
+       <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
+     </intent-filter>
+   </service>

    ...

Edit android/app/build.gradle:

NOTE: after v16.0.0, Android target SDK has be to >= 26 and build tool has to be >= 26.0.x

NOTE: Make sure the version matches this library.

+ compileSdkVersion 27
+    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "com.google.firebase.quickstart.fcm"
        minSdkVersion 16
+        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

 dependencies {
+    compile project(':react-native-fcm')
     compile fileTree(dir: "libs", include: ["*.jar"])
     compile "com.facebook.react:react-native:+"  // From node_modules
 }
 
 //bottom
 + apply plugin: "com.google.gms.google-services"

If you are using other firebase libraries, check this for solving dependency conflicts https://github.com/evollu/react-native-fcm/blob/master/Examples/simple-fcm-client/android/app/build.gradle#L133

Edit android/settings.gradle

  ...
+ include ':react-native-fcm'
+ project(':react-native-fcm').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fcm/android')
  include ':app'
  • Edit MainActivity.java. This fixes a bug
+ import android.content.Intent;
...
public class MainActivity extends ReactActivity {
+ @Override
+    public void onNewIntent(Intent intent) {
+        super.onNewIntent(intent);
+        setIntent(intent);
+    }
}

Make sure in MainApplication.java you have the code below:

NOTE: The packages listed inside should appear once only. react-native link sometimes can mess up this part, please remove duplicated packeges.

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new MapsPackage(),
+           new FIRMessagingPackage()
      );
    }

+ @Override
+  public void onCreate() { // <-- Check this block exists
+    super.onCreate();
+    SoLoader.init(this, /* native exopackage */ false); // <-- Check this line exists within the block
+  }

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:

Edit AndroidManifest.xml:

  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:windowSoftInputMode="adjustResize"
+   android:launchMode="singleTop"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>

Notes:

  • launchMode="singleTop" is to reuse MainActivity, you can use singleTask or singleInstance as well depend on your need. this link explains the behavior well
  • you if want to handle click_action you need to add custom intent-filter, check native android documentation

If you are using RN < 0.30.0 and react-native-fcm < 1.0.16, pass intent into package, edit MainActivity.java:

  • RN 0.28:
  import com.facebook.react.ReactActivity;
+ import android.content.Intent;

  public class MainActivity extends ReactActivity {

+   @Override
+   public void onNewIntent (Intent intent) {
+     super.onNewIntent(intent);
+       setIntent(intent);
+   }       

NOTE: Verify that react-native links correctly in MainApplication.java

import android.app.application
...
+import com.evollu.react.fcm.FIRMessagingPackage;

....

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new VectorIconsPackage(),
+         new FIRMessagingPackage(),
          new RNDeviceInfo(),
      );
    }
  • RN <= 0.27:
  import com.facebook.react.ReactActivity;
+ import android.content.Intent;

  public class MainActivity extends ReactActivity {

+   @Override
+   protected void onNewIntent (Intent intent) {
+     super.onNewIntent(intent);
+       setIntent(intent);
+   }       

Notes:

  • @Override is added to update intent on notification click

IOS Configuration

Pod approach:

Make sure you have Cocoapods version > 1.0

Configure the project:

cd ios && pod init

(In case of syntax errors, open YOURApp.xcodeproj/project.pbxproj and fix them.)

Edit the newly created Podfile:

  # Pods for YOURAPP
+ pod 'Firebase'
+ pod 'Firebase/Messaging'

Install the Firebase/Messaging pod:

pod install

NOTE: you don't need to enable use_frameworks!. if you have to have use_frameworks! make sure you don't have inherit! :search_paths

NOTE: there is a working example in master branch

NOTE: If you don't put pod 'Firebase' into Podfile, compilation will fail with error of missing Firebase library.

Non Cocoapod approach

  1. Follow the instruction on Integrate without CocoaPods.
  • Import libraries, add Capabilities (background running and push notification), upload APNS and etc etc etc...
  1. Put frameworks under ios/Frameworks folder, and drag those files into your xcode solution -> Frameworks
  2. Put firebase.h and module.modulemap under ios/Frameworks folder, no need to drag into solution
  3. Modify your project's User Header Search Paths and add $(PROJECT_DIR)/Frameworks

screen shot 2018-03-05 at 2 17 03 pm

NOTE: There is a working example in `no-pod` branch

Shared steps

Edit AppDelegate.h:

+ @import UserNotifications;
+
+ @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
- @interface AppDelegate : UIResponder <UIApplicationDelegate>

Edit AppDelegate.m:

+ #import "RNFIRMessaging.h"
  //...

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
  //...
+   [FIRApp configure];
+   [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];

    return YES;
 }

+
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
+ {
+   [RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
+ }
+
+ #if defined(__IPHONE_11_0)
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
+ {
+   [RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
+ }
+ #else
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler
+ {
+   [RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
+ }
+ #endif
+
+ //You can skip this method if you don't want to use local notification
+ -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
+   [RNFIRMessaging didReceiveLocalNotification:notification];
+ }
+
+ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
+   [RNFIRMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
+ }

Add the path of header files into XCode:

  1. Open XCode.
  2. Press CMD+1 or click the XCode project.
  3. Go to Build Settings, selecting All and Combined.
  4. Search Header Search Path in the searchg tab.
  5. Make sure there is a line of $(SRCROOT)/../node_modules/react-native-fcm/ios. If no, just add it.

Add GoogleService-Info.plist:

Make sure the file is not just moved into the folder. You need to Right Click the project folder in XCode and Add File to <Project Name>. Select Copy if needed in the Options page while selecting the file.

Shared Library Settings:

  • Make sure you see Pods.xcodeproj under Library folder if you are using Pod install method.
  • Make sure you see RNFIRMessaging.xcodeproj under Library folder.
  • If you don't see any of these files, please add them by Right Click the Library folder and Add File to <Project Name> to add them back. Pods.xcodeproj should be under ios/Pods/, and RNFIRMessaging.xcodeproj should be under node_modules/react-native-fcm/ios.
  • Make sure you see libRNFIRMessaging.a under Link Binary With Libraries under Build Phases tab. If no, drag the file under RNFIRMessaging.xcodeproj under Library folder into there.

Add Capabilities

  • Select your project Capabilities and enable:
    • Push Notifications
    • Background Modes > Remote notifications.

FirebaseAppDelegateProxyEnabled

This instruction assumes that you have FirebaseAppDelegateProxyEnabled=YES (default) so that Firebase will hook on push notification registration events. If you turn this flag off, you will be on your own to manage APNS tokens and link with Firebase token.

Setup Local Notifications

NOTE: local notification does NOT have any dependency on FCM library but you still need to include Firebase to compile. If there are enough demand to use this functionality alone, I will separate it out into another repo

IOS

No change required

Android

Edit AndroidManifest.xml

  <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <uses-permission android:name="android.permission.VIBRATE" />

  <application>
+      <receiver android:name="com.evollu.react.fcm.FIRLocalMessagingPublisher"/>
+      <receiver android:enabled="true" android:exported="true"  android:name="com.evollu.react.fcm.FIRSystemBootEventReceiver">
+          <intent-filter>
+              <action android:name="android.intent.action.BOOT_COMPLETED"/>
+              <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
+              <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
+              <category android:name="android.intent.category.DEFAULT" />
+          </intent-filter>
+      </receiver>
  </application>

NOTE: com.evollu.react.fcm.FIRLocalMessagingPublisher is required for presenting local notifications. com.evollu.react.fcm.FIRSystemBootEventReceiver is required only if you need to schedule future or recurring local notifications

Usage

Check example project

Build custom push notification for Android

Firebase android misses important feature of android notification like group, priority and etc. As a work around you can send data message (no notification payload at all) and this repo will build a local notification for you. If you pass custom_notification in the payload, the repo will treat the content as a local notification config and shows immediately.

NOTE: By using this work around, you will have to send different types of payload for iOS and Android devices because custom_notification isn't supported on iOS

WARNING: custom_notification cannot be used together with notification attribute. use data ALONE

Example of payload that is sent to FCM server:

{
  "to":"FCM_TOKEN",
  "data": {
    "type":"MEASURE_CHANGE",
    "custom_notification": {
      "body": "test body",
      "title": "test title",
      "color":"#00ACD4",
      "priority":"high",
      "icon":"ic_notif",
      "group": "GROUP",
      "id": "id",
      "show_in_foreground": true
    }
  }
}

Example of payload that is sent through firebase console: screen shot 2018-04-04 at 1 18 09 pm

Check local notification guide below for configuration.

IMPORTANT: When using the admin.messaging API, you need to JSON.stringify the custom_notification value:

let tokens = [...];
let payload = {
  data: {
    custom_notification: JSON.stringify({
      body: 'Message body',
      title: 'Message title'
      ...
    })
  }
};
let options = { priority: "high" };

admin
  .messaging()
  .sendToDevice(tokens, payload, options);

Behaviour when sending notification and data payload through GCM

  • When user clicks notification to launch the application, you can get that notification by calling FCM.getInitialNotification. (NOTE: reloading javascript or resuming from background won't change the value)

  • When app is running in background (the tricky one, I strongly suggest you try it out yourself)

  • IOS will receive notificaton from FCMNotificationReceived event

    • if you pass content_available flag true, you will receive one when app is in background and another one when user resume the app. more info
    • if you just pass notification, you will only receive one when user resume the app.
    • you will not see banner if notification->body is not defined.
  • Android will receive notificaton from FCMNotificationReceived event

    • 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:

    {
       "to":"some_device_token",
       "content_available": true,
       "notification": {
           "title": "hello",
           "body": "yo",
           "click_action": "fcm.ACTION.HELLO"
       },
       "data": {
           "extra":"juice"
       }
     }

    and event callback will receive as:

    • Android

      {
        "fcm": {"action": "fcm.ACTION.HELLO"},
        "opened_from_tray": 1,
        "extra": "juice"
      }
    • iOS

      {
        "apns": {"action_category": "fcm.ACTION.HELLO"},
        "opened_from_tray": 1,
        "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 separate data message.)

NOTE: it is recommended not to rely on data payload for click_action as it can be overwritten (check this).

Quick notes about upstream messages

If your app server implements the XMPP Connection Server protocol, it can receive upstream messages from a user's device to the cloud. To initiate an upstream message, call the FCM.send() method with your Firebase Sender ID and a Data Object as parameters as follows:

FCM.send('984XXXXXXXXX', {
  my_custom_data_1: 'my_custom_field_value_1',
  my_custom_data_2: 'my_custom_field_value_2'
});

The Data Object is message data comprising as many key-value pairs of the message's payload as are needed (ensure that the value of each pair in the data object is a string). Your Sender ID is a unique numerical value generated when you created your Firebase project, it is available in the Cloud Messaging tab of the Firebase console Settings pane. The sender ID is used to identify each app server that can send messages to the client app.

Sending remote notifications with category on iOS

If you want to send notification which will have actions as you defined in app it's important to correctly set it's category (click_action) property. It's also good to set "content-available" : 1 so app will gets enough time to handle actions in background.

So the fcm payload should look like this:

{
   "to": "some_device_token",
   "content_available": true,
   "notification": {
       "title": "Alarm",
       "subtitle": "First Alarm",
       "body": "First Alarm",
       "click_action": "com.myapp.MyCategory" // The id of notification category which you defined with FCM.setNotificationCategories
   },
   "data": {
       "extra": "juice"
   }
 }

Q & A

Why do you build another local notification

Yes there are react-native-push-notification and react-native-system-notification which are great libraries. However

  • We want a unified local notification library but people are reporting using react-native-push-notification with this repo has compatibility issue as react-native-push-notification also sets up GCM.
  • We want to have local notification to have similar syntax as remote notification payload.
  • The PushNotificationIOS by react native team is still missing features that recurring, so we are adding it here

My Android build is failing

Try update your SDK and google play service. If you are having multiple plugins requiring different version of play-service sdk, skip conflicting group. The example project shows for how to colive with react-native-maps

    compile(project(':react-native-maps')) {
        exclude group: 'com.google.android.gms', module: 'play-services-base'
    }

My App throws FCM function undefined error

There seems to be link issue with rnpm. Make sure that there is new FIRMessagingPackage(), in your Application.java file

I can't get notification in iOS emulator

Remote notification can't reach iOS emulator since it can't fetch APNS token. Use real device.

I'm not getting notfication when app is in background

  1. Make sure you've uploaded APNS certificates to Firebase and test with Firebase's native example to make sure certs are correct
  2. Try simple payload first, sometimes notification doesn't show up because of empty body, wrong sound name etc.

App running in background doesn't trigger FCMNotificationReceived when receiving hybrid notification [Android]

These is an issue opened for that. Behavior is not consistent between 2 platforms

Android notification is showing a white icon

Since Lollipop, the push notification icon is required to be all white, otherwise it will be a white circle.

iOS not receiving notification when the app running in the background

  • Try adding Background Modes permission in Xcode->Click on project file->Capabilities tab->Background Modes->Remote Notifications

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.**

I'm getting com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzqf;

It is most likely that you are using other react-native-modules that requires conflicting google play service search for compile "com.google.android.gms in android and see who specifies specific version. Resolve conflict by loosing their version or specify a version resolve in gradle. Check this article https://medium.com/@suchydan/how-to-solve-google-play-services-version-collision-in-gradle-dependencies-ef086ae5c75f#.9l0u84y9t

How do I tell if user clicks the notification banner?

Check open from tray flag in notification. It will be either 0 or 1 for iOS and undefined or 1 for android. I decide for iOS based on this, and for android I set it if notification is triggered by intent change.

Android notification doesn't vibrate/show head-up display etc

All available features are here. FCM may add more support in the future but there is no timeline. In the mean time, you can pass "custom_notification" in a data message. This repo will show a local notification for you so you can set priority etc

How do I do xxx with FCM?

check out official docs and see if they support

I want to add advanced feature that FCM doesn't support for remote notification

You can either wait for FCM to develop it or you have to write native code to create notifications.

  • for iOS, you can do it in didReceiveRemoteNotification in appDelegate.m
  • for android, you can do it by implementing a service similar to "com.evollu.react.fcm.MessagingService"

Or if you have a good way to wake up react native javascript thread please let me know, although I'm worring waking up the whole application is too expensive.

What about new notifications in iOS 10

Congratulations, now you have 5 notification handler to register! in sum

  • willPresentNotification is introduced in iOS 10 and will only be called when local/remote notification will show up. This allows you to run some code before notification shows up. You can also decide how to show the notification.
  • didReceiveNotificationResponse is introduced in iOS 10 and provides user's response together with local/remote notification. It could be swipe, text input etc.
  • didReceiveLocalNotification is for iOS 9 and below. Triggered when user clicks local notification. replaced by didReceiveNotificationResponse
  • didReceiveRemoteNotification is for iOS 9 and below. Triggered when remote notification received.
  • didReceiveRemoteNotification:fetchCompletionHandler is for both iOS 9 and 10. it gets triggered 2 times for each remote notification. 1st time when notification is received. 2nd time when notification is clicked. in iOS 9, it serves us the purpose of both willPresentNotification and didReceiveNotificationResponse but for remote notification only. in iOS 10, you don't need it in most of the case unless you need to do background fetching

Great, how do I configure for FCM? It is up to you! FCM is just a bridging library that passes notification into javascript world. You can define your own NSDictionary and pass it into notification.

I want to show notification when app is in foreground

Use show_in_foreground attribute to tell app to show banner even if the app is in foreground.

NOTE: this flag doesn't work for Android push notification, use custom_notification to achieve this.

NOTE: foreground notification is not available on iOS 9 and below

Do I need to handle APNS token registration?

No. Method swizzling in Firebase Cloud Messaging handles this unless you turn that off. Then you are on your own to implement the handling. Check this link https://firebase.google.com/docs/cloud-messaging/ios/client

I want to add actions in iOS notification

Check this #325

React/RCTBridgeModule.h not found

This is mostly caused by React Native upgrade. Here is a fix http://stackoverflow.com/questions/41477241/react-native-xcode-upgrade-and-now-rctconvert-h-not-found

Some features are missing

Issues and pull requests are welcome. Let's make this thing better!

Credits

Local notification implementation is inspired by react-native-push-notification by zo0r

I get the notifications in the logs, but the native prompt does not show up

Did you remember to ask the user permissions? ;)

await FCM.requestPermissions({ badge: false, sound: true, alert: true })

Sending remote notification

How to send a push notification from your server? You should POST to this endpoint:

https://fcm.googleapis.com/fcm/send

You need to set the headers of Content-Type to application/json and Authorization to key=****** where you replace ****** with the "Legacy server key" from here the Firebase dashbaord. Get this information by first going to:

  1. https://console.firebase.google.com/
  2. Click on "Gear" icon and click "Project Settingss". Screenshot: https://screenshotscdn.firefoxusercontent.com/images/35b93de8-44e1-49af-89d7-140b74c267c7.png
  3. Click on "Cloud Message" tab and find "Legacy server key" here. Screenshot: https://screenshotscdn.firefoxusercontent.com/images/c52ec383-783d-47d3-a1e6-75249fb6f3fb.png

The body should be json like this:

{
  "to":"FCM_DEVICE_TOKEN_GOES_HERE",
  "data": {
    "custom_notification": {
      "body": "test body",
      "title": "test title",
      "color":"#00ACD4",
      "priority":"high",
      "icon":"ic_launcher",
      "group": "GROUP",
      "sound": "default",
      "id": "id",
      "show_in_foreground": true
    }
  }
}

Example:

fetch('https://fcm.googleapis.com/fcm/send', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
        'Authorization': 'key=EFefklefwef9efwefkejfwf'
    },
    body: JSON.stringify({
        "to":"kajfsdf:efawefwe_fsdfdsf-asfawefwefwf_asdfsdfasd-asdfasdfsd9A_asdfsdf_asdf",
        "data": {
            "custom_notification": {
            "body": "test body",
            "title": "test title",
            "color":"#00ACD4",
            "priority":"high",
            "icon":"ic_notif",
            "group": "GROUP",
            "sound": "default",
            "id": "id",
            "show_in_foreground": true
            }
        }
    })
})

Channels

Right now for Android Orion 8 or API 26 is important to use channels. Firebase will create a default channel for you or you can custom your default channel for Firebase notifications by adding default meta data to AndroidManifest:

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id"/>

more reading on official docs

However it is essential to create a notification channel if you need to show local notification or use custom_notification. First you should createNotificationChannel on init app. Its creates if not exists yet.

FCM.createNotificationChannel({
    id: 'car_status',
    name: 'Car status',
    description: 'Notifies when changes car status',
    priority: 'max',
});

After this all notifications should have channel key and value with specified channel name. For example:

customNotification = {
   id: 'id',
   title: `title`,
   body: 'body',
   sound: 'default',
   priority: 'high',
   icon: 'ic_launcher',
   show_in_foreground: true,
   vibrate: 500,
   channel: 'car_status', <====
   action: 'android.intent.action.MAIN',
};

react-native-fcm's People

Contributors

cooperka avatar danieloprado avatar dimon70007 avatar ditkachuk avatar douglasjunior avatar ethan37 avatar evollu avatar haggholm avatar janicduplessis avatar kazuyakitahara avatar krystofcelba avatar ksegla avatar mjmasn avatar moriyoshi avatar noitidart avatar ptomasroos avatar punksta avatar rafaelfs avatar riyaz942 avatar sergchr avatar simonexmachina avatar slycoder avatar the-simian avatar titozzz avatar tolu360 avatar wcandillon avatar willlaserlike avatar windhamwong avatar xxsnakerxx avatar yangtaufoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-fcm's Issues

[Android] Unexpected behavior in inactive state

When in inactive state, I get the same notification twice if send "notification" from fcm. And no notification at all if I use "data". And if I use both data and notification, I get the same notification twice. I am using react-native-push-notification as well to show local notifications. Could that be the reason? And where can I override this? I think there is something wrong with my AndroidManifest.xml

Simply, I want to show banner notification (local notification) even when the app is killed. Like other normal apps.

Thanks

UPDATE: I also found out that if I inlcude react-native-push-notification and react-native-fcm libraries in the same page then there is no icon in banner notification.

[android] heads-up notification

How to show heads-up notification on android?
I am using the following payload from fcm.

{
    to: <deviceToken>,
    priority: 'high',
    data: {
        custom_data_key: 'custom_data_value'
    },
    notification: {
        title: 'Push notification test',
        body: message,
        click_action: 'fcm.ACTION.HELLO',
        sound: 'default'
    }
}

Multiple notifications

Can anyone give me an example about how to retrieve multiple notifications' data?
When using FCM.initialData, it seems to get only the data of the notifcation you've just clicked.

registerForRemoteNotifications

Hi,

I'm struggling to get the remote push notifications working on IOS.
Reading through the documentation I found that registerForRemoteNotifications should be called to allow remote push notifications to be received. However in the code I only see registerUserNotificationSettings being called.
I also read that on macOS you only need to call that method and it will call the registerForRemoteNotifications for you, however on iOS it seems you'd have to explicitly call that method for remote push notifications to work.

Am I missing something in the documentation or should this method be called?

Use of undeclared identifier 'FCMNotificationReceived'

After following your installation guide (following the 'Non Cocoapod approach'), and pasting in this code:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {
  [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification];
  handler(UIBackgroundFetchResultNewData);
}

I get the following error: Use of undeclared identifier 'FCMNotificationReceived'

Any idea why?

Pretty sure I added all the files the right way.

Undefined symbols for architecture armv7:

After implementing the readme the build directly on a device fails with these errors:

Undefined symbols for architecture armv7: "_OBJC_CLASS_$_FIRApp", referenced from: objc-class-ref in AppDelegate.o "_OBJC_CLASS_$_FIRInstanceID", referenced from: objc-class-ref in libRNFIRMessaging.a(RNFIRMesssaging.o) "_OBJC_CLASS_$_FIRMessaging", referenced from: objc-class-ref in libRNFIRMessaging.a(RNFIRMesssaging.o) "_kFIRInstanceIDTokenRefreshNotification", referenced from: -[RNFIRMessaging setBridge:] in libRNFIRMessaging.a(RNFIRMesssaging.o) ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

also these warnings:
ld: warning: object file (/PATH-byxbzdyvvunexgaoyfngwacuplnc/Build/Products/Debug-iphoneos/libPods-Starmind.a(Pods-App-dummy.o)) was built for newer iOS version (9.0) than being linked (7.0) ld: warning: Auto-Linking supplied '/PATH/App/ios/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/FirebaseInstanceID', framework linker option at /PATH/App/ios/Pods/FirebaseInstanceID/Frameworks/FirebaseInstanceID.framework/FirebaseInstanceID is not a dylib

Any hints what I might be doing wrong? Thanks!

error: cannot find symbol - new FIRMessagingPackage(getIntent())

Hey, i want to use your react-native-fcm in my app.
there are only react-native and your react-native-fcm.
I made all steps from readme, but i cant build app.
paste error:

../../../MainActivity.java:47: error: cannot find symbol
new FIRMessagingPackage(getIntent())
^
symbol: class FIRMessagingPackage
location: class MainActivity

Best way to handle vibrations/sounds when receiving notification?

Hi!

Sorry if this is out of scope of this package, but what is the best way to make an android device vibrate or play a sound when a notification comes in? Is this something that should be implemented in onMessageReceived within MessagingService.java? Or is this in the scope of firebase rather than RN?

Receive notifications when app is closed

The push notifications are working well when the app is opened or running in the background.
Is there also a possibility to receive messages when the app is closed?

Attempting to assign weaker access privileges; was public

This is more a FYI: When initiating a new Project and implementing your Readme step by step I got this issue:
/MainActivity.java:34: error: onNewIntent(Intent) in MainActivity cannot override onNewIntent(Intent) in ReactActivity protected void onNewIntent(Intent intent){ ^ attempting to assign weaker access privileges; was public 1 error :app:compileDebugJavaWithJavac FAILED

How to detect notification open when app running background?

I implemented the notification handling for the states of foreground-running and not-running. But when the app is in background and users click on the notification, how does the app detect that and run the same code as the not-running case?

Thanks

Can I use this with react-native-system-notification?

Hey,

So after getting everything working last night, I was curious how you get the actual notification to show up. Is that when you use a library like react-native-system-notification?

Did you get any compatibility issues with it since it supports GCM and not FCM?

Thanks again!

Android dependency conflict [DexException]

Hi @evollu, thanks for providing this awesome module!

I have a project that used react-native-google-signin module. When I added your project (react-native-fcm), the project couldn't be compiled and produced the following errors:

Error:Gradle: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/measurement/AppMeasurementContentProvider;

Error:Gradle: Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

I have tried to use multiDexEnabled true, however it produces even more conflicts.

Do you have any suggestion to solve this issue? By the way, the react-native-google-signin was able to work with react-native-gcm-push-notification.

Thanks anyway.

Create releases and release notes

Hi,

I see there are many releases. But before I'm going to version bump my dependencies I'd like to know why by reading release notes.

Is it possible to supply small release notes as a git release or something?

Many thanks!

Working only for 1st message.

I have added following code in my main file:

  • (void)applicationDidEnterBackground:(UIApplication *)application {
    // [[FIRMessaging messaging] disconnect];
    NSLog(@"Disconnected from FCM");
    }

//add this

  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification {
    [[NSNotificationCenter defaultCenter] postNotificationName: FCMNotificationReceived
    object:self
    userInfo:notification];

}

//add this

  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {
    [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived
    object:self
    userInfo:notification];
    handler(UIBackgroundFetchResultNoData);
    }

the notification is shown only once when app runs for 1st time after installation

Please consider to use semantic versioning

Some people might just check status of their dependencies via npm outdated and if they see just patch update, they can assume that they can safely update.
It does not happen to me but I find semver as useful convention :)

iOS example Project ?

no matter what I do or which computer I use or how many clean installs I try... I also updated every component of development... iOS project crashes.

Could you include a sample project for iOS that works?

Icons do not work on Android

The icon parameter is not being properly set by Firebase

It tries to set the launcher icon as the backup but that fails as well. During my testing the icon was set to a random system icon like pause or stop.

I setup my own services with firebase and then the icon property was being read properly.

Build error ios in xcode

Getting a build error on:
../node_modules/react-native-fcm/ios/RNFIRMesssaging.m:74:20: No known class method for selector 'messaging'

screen shot 2016-07-14 at 10 28 22

[android] not compatible with proguard

When I enable proguard, it does build but the app crashes right before starting.

:app:proguardRelease
Warning: com.google.android.gms.internal.zzw$zza: can't find superclass or interface org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning: com.google.android.gms.internal.zzac: can't find referenced class android.net.http.AndroidHttpClient
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.StatusLine
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.HttpEntity
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzt: can't find referenced class org.apache.http.Header
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpDelete
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpHead
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpOptions
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpTrace
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.entity.ByteArrayEntity
Warning: com.google.android.gms.internal.zzw: can't find referenced method 'void addHeader(java.lang.String,java.lang.String)' in program class com.google.android.gms.internal.zzw$zza
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpDelete
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpHead
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpOptions
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPost
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpPut
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpTrace
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.entity.ByteArrayEntity
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.HttpClient
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.google.android.gms.internal.zzw$zza: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzw$zza: can't find referenced method 'void setURI(java.net.URI)' in program class com.google.android.gms.internal.zzw$zza
Warning: com.google.android.gms.internal.zzw$zza: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateParseException
Warning: com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzx: can't find referenced class org.apache.http.impl.cookie.DateUtils
Warning: com.google.android.gms.internal.zzy: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzy: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.ProtocolVersion
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHeader
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicStatusLine
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.ProtocolVersion
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.entity.BasicHttpEntity
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHeader
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicHttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.message.BasicStatusLine
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpResponse
Warning: com.google.android.gms.internal.zzz: can't find referenced class org.apache.http.HttpEntity
Warning: there were 87 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 2 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile the code.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Exception while processing task
java.io.IOException: Please correct the above warnings first.
    at proguard.Initializer.execute(Initializer.java:473)
    at proguard.ProGuard.initialize(ProGuard.java:233)
    at proguard.ProGuard.execute(ProGuard.java:98)
    at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
    at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:139)
    at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:115)
    at com.android.builder.tasks.Job.runTask(Job.java:48)
    at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
    at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227)
    at java.lang.Thread.run(Thread.java:745)
:app:dexRelease

Non correct linking instruction

As said in installation instructions:

Run react-native link react-native-fcm

but when i did it i got error:

rnpm-link info Linking react-native-fcm android dependency
rnpm-link ERR! It seems something went wrong while linking. Error: path must be a string
Please file an issue here: https://github.com/rnpm/rnpm/issues
/PROJECT_PATH/node_modules/promise/lib/done.js:10
throw err;
^

TypeError: path must be a string
at TypeError (native)
at Object.fs.openSync (fs.js:584:18)
at Object.fs.readFileSync (fs.js:431:33)
at applyPatch (/PROJECT_PATH/node_modules/react-native/local-cli/rnpm/link/src/android/patches/applyPatch.js:6:29)
at registerNativeAndroidModule (/PROJECT_PATH/node_modules/react-native/local-cli/rnpm/link/src/android/registerNativeModule.js:23:3)
at /PROJECT_PATH/node_modules/react-native/local-cli/rnpm/link/src/link.js:43:5
at process._tickCallback (node.js:406:9)
at Function.Module.runMain (module.js:449:11)
at startup (node.js:141:18)
at node.js:933:3

So i did it like:
react-native link 'react-native-fcm'
And it worked fine

Android crashes when receiving notification

I'm running into the following issue when using the latest [email protected] and [email protected]

I have setup the package as outlined in the documentation with the only thing still not quite clear to me whether to add the public onNewIntent() method to MainActivity.java. i get the same crash whether i add it or not though so it does not seem to make a difference.

I thnk the docs are a bit unclear here since RN>0.29 apps now use MainApplication.java for additional activity methods as far as i can tell.

Either way, what happens is; while notifications are received fine on the device (tested on simulator) once a notification is received when the app is not in focus or started and you start the app it immediately crashes.

I get the following stack trace from Android Studio:

07-28 16:13:53.355 4733-4733/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.florinapp.florinapp.debug, PID: 4733
                                                 java.lang.AbstractMethodError: abstract method "void com.facebook.react.bridge.ActivityEventListener.onNewIntent(android.content.Intent)"
                                                     at com.facebook.react.bridge.ReactContext.onNewIntent(ReactContext.java:169)
                                                     at com.facebook.react.ReactInstanceManagerImpl.onNewIntent(ReactInstanceManagerImpl.java:483)
                                                     at com.facebook.react.ReactActivity.onNewIntent(ReactActivity.java:183)
                                                     at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1223)
                                                     at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1235)
                                                     at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2783)
                                                     at android.app.ActivityThread.performNewIntents(ActivityThread.java:2795)
                                                     at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2804)
                                                     at android.app.ActivityThread.-wrap15(ActivityThread.java)
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1539)
                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                     at android.os.Looper.loop(Looper.java:154)
                                                     at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Handling push notification

@evollu, is there any way to get an actual push notification on android devices?
Currently, it looks like this package handles only the connection with FCM. Another package you have, react-native-gcm-push-notification, or the package react-native-push-notification let you create a notification too but unfortunately they use GCM.
Any thoughts?

Thanks

Android

I am having trouble integrating FCM in Android, it is working perfectly in IOS with this component.
But in Android I am getting this error:

node_modules/react-native-fcm/android/src/main/java/com/evollu/react/fcm/FIRMessagingModule.java:159: error: method does not override or implement a method from a supertype @Override ^

Maybe there is any error in the README? Because there is a different config for RN0.28+ and RN <= 0.27, but both are identical.

image

Btw, I am using RN 0.28.0
Thank you for your help!

to pod or not to pod

With recent issues opened regarding ios integration, I'm thinking about supporting projects not using cocoapods.
Pro of not using it

  1. There is no extra workspace file and react-native run-ios will be working again
  2. Less issue on installation
    Cons
  3. Official docs recomends cocoapods
  4. Updating framework is more intrusive

Looks like supporting both of the approach is not possible, so what do you think?

RN 0.29 android config

With the latest changes, the getPackages method has been moved to an application class, and are no longer in the main activity. As such, this call is no longer possible:

new FIRMessagingPackage(getIntent())

How do I set up react-native-fcm on android when using RN 29?

[android] initialNotification

is there a way we can get initialNotification payload like on ios when user click on notification?
I have found in the firebase api that there is a way to specify activity using click_action and handle new activity but I am not sure how to implement that because I am not that much familiar with Android development

<intent-filter>
  <action android:name="OPEN_ACTIVITY_1" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

btw thank you for this awesome module

Cannot find variable DeviceEventEmitter - update docs

Hi,
Please update the docs that DeviceEventEmitter should be imported from 'react-native'.

Something like:
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View,
DeviceEventEmitter
} from 'react-native';

[Android] Package com.evollu.react.fcm does not exist

I installed the package react-native-fcm on my project and my project cannot compile. It keeps alerting that com.evollu.react.fcm.FIRMessagingPackage does not exist.
How to fix this problem?
I am using RN 0.28.0 .
Any help is appreciated.

How can I access the notification data

Hi

First of all I'd like to thank you for developing this project! I am currently getting started with react-native / firebase development and so far I am amazed by the amount of available open source code and the community.

However since I am only getting started I am quite confused with the whole push notification / FCM concept.

I followed this tutorial and the one in the readme of this repo. I am able to send notifications from the firebase console and they are displayed as a notification on the iPhone but only if the app is running in the background.

  • How can I access the content of the notification when the user clicks on a notification?
  • Or when the app is running in the foreground?
  • Do I need to use the PushNotificationIOS methods / events?
  • What does "IOS will receive notificaton from FCMNotificationReceived event" mean?
  • How can I set the "content_available" flag to true in the Firebase Console?

I've read the readme and had a look at your code sample but couldn't figure it out on my own.
Any help or a link for further reading would be highly appreciated.

Thanks,
Michael

[iOS] Firebase headers error when building project

Hi, I'm installed react-native-fcm, like described in README, (npm install, rnpm link, created pod file and runned pod install)
Pods installed fine, my Podfile contains:

# Uncomment this line to define a global platform for your project
# platform :ios, '6.0'
pod 'Firebase'
pod 'Firebase/Core'
pod 'Firebase/Analytics'
pod 'Firebase/Messaging'

target 'MyApp' do
end

target 'MyAppTests' do
end

I'm using .xcworkspace file to open the project, but I get this error:
/Users/me/Projects/MyApp/ios/Pods/Firebase/Headers/Firebase.h:1:9: 'FirebaseAnalytics/FirebaseAnalytics.h' file not found and cannot build my project.
$(inherited) added to Header Search Path and to Other Linker Flags
Any suggestions?

vibrate

Hi,

Is it possible to vibrate the device (iOS and Android) when there is a notification?

Thanks,
Gary

Firebase sdk dependencies

Is it necesery to add compile "com.google.firebase:firebase-core:9.2.1" or compile 'com.google.firebase:firebase-messaging:9.2.1' in build.gradle?
Same question for react-native-firebase-analytics.

Thanks.

[iOS] Not showing notification banner when app running in Background

@evollu I have created a React Native Project and added the "react-native-fcm" for the Push Notification Support. In android i am able to run the app as expected.

But in iOS, if the app is in foreground, I am getting the notification(I have added some console.log in the "notification" event). But when I push the app background then I am not able to see the notification Banner.

Is I am missing anything?

Couldn't get it to work with react-native-push-notification

Since its clearly mentioned on the home page that notifications do not appear when the app is in foreground on android, I chose to trigger notifications locally in that particular case using [email protected](I'm using [email protected]).

I can not get it to work with react-native-fcm. My gradle builds fail with the following error. Please help!

Error:Execution failed for task ':app:processDebugResources'.
> Error: more than one library with package name 'com.google.android.gms'

FCM token is null

FCM.getFCMToken().then(token => {
console.log(token)
// store fcm token in your server
});

In console Null is printed.(For ANDROID didn't tried on IOS)

[IOS] Error with Setup

Hey,

If I try to use this package, and try to write [FIRApp configure]; I get an error that this command is undefined.

Any Ideas or suggestions?

Thanks
Alex

ClassNotFoundException com.evollu.react.fcm.InstanceIdService

any idea what is missing?

E/AndroidRuntime(19958): java.lang.RuntimeException: Unable to instantiate service com.evollu.react.fcm.InstanceIdService: java.lang.ClassNotFoundException: Didn't find class "com.evollu.react.fcm.InstanceIdService" on path: DexPathList[[zip file "/data/app/com.zib100-1/base.apk"],nativeLibraryDirectories=[/data/app/com.zib100-1/lib/arm, /vendor/lib, /system/lib]]
E/AndroidRuntime(19958): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2776)
E/AndroidRuntime(19958): at android.app.ActivityThread.access$1800(ActivityThread.java:155)
E/AndroidRuntime(19958): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1400)
E/AndroidRuntime(19958): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(19958): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(19958): at android.app.ActivityThread.main(ActivityThread.java:5343)
E/AndroidRuntime(19958): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(19958): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(19958): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
E/AndroidRuntime(19958): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
E/AndroidRuntime(19958): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.evollu.react.fcm.InstanceIdService" on path: DexPathList[[zip file "/data/app/com.zib100-1/base.apk"],nativeLibraryDirectories=[/data/app/com.zib100-1/lib/arm, /vendor/lib, /system/lib]]
E/AndroidRuntime(19958): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(19958): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(19958): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(19958): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2773)
E/AndroidRuntime(19958): ... 9 more
E/AndroidRuntime(19958): Suppressed: java.lang.ClassNotFoundException: com.evollu.react.fcm.InstanceIdService
E/AndroidRuntime(19958): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(19958): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(19958): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(19958): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(19958): ... 11 more
E/AndroidRuntime(19958): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
W/ActivityManager( 838): Force finishing activity 1 com.zib100/.MainActivity

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.