Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Fetch firestore Docs in react native headless js using fcm data only messages when my app closed by user #1391

Closed
naveenkumardot25 opened this issue Aug 11, 2018 · 2 comments

Comments

@naveenkumardot25
Copy link

naveenkumardot25 commented Aug 11, 2018

Issue

Environment

Android

  1. Application Target Platform: Windows 10
  2. Development Operating System: Android Studio version, Android SDK version
  3. Build Tools: 0.55.3
  4. React Native version: 0.55.3
  5. RNFirebase Version: "^4.3.6"
  6. Firebase Module:

My index.js file:

import { AppRegistry } from 'react-native';
import Switch from './src/Switch';
import bgMessaging from './src/bgMessaging';

AppRegistry.registerComponent('******', () => Switch);
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging); 

My bgMessaging file:

import firebase from './firebase';
import { RemoteMessage } from 'react-native-firebase';

export default bgMessaging = async(message) => {
    firebase.messaging().onMessage((message) => {
        firebase.firestore().doc(`Messages/${message.data.Doc_Id}`).get();
    });
    return Promise.resolve();
}

My AndroidManifest.xml file:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.movny.movny"
   android:versionCode="1"
   android:versionName="1.0">
   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
   <uses-permission android:name="android.permission.CAMERA" />
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

   <application
     android:name=".MainApplication"
     android:allowBackup="true"
     android:label="@string/app_name"
     android:icon="@mipmap/ic_launcher"
     android:theme="@style/AppTheme">
     <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
     <activity
       android:name=".MainActivity"
       android:label="@string/app_name"
       android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
       android:windowSoftInputMode="adjustResize">
       <intent-filter>
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
     </activity>
     <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
     <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
       <intent-filter>
         <action android:name="com.google.firebase.MESSAGING_EVENT" />
       </intent-filter>
     </service>
     <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
       <intent-filter>
         <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
       </intent-filter>
     </service>
   </application>

</manifest>

My Build.gradle version :

compileSdkVersion 27
defaultConfig {
minSdkVersion 18
targetSdkVersion 27
versionCode 1
versionName "1.0"
}

Can anyone help me How to achieve this thing?

@naveenkumardot25
Copy link
Author

naveenkumardot25 commented Aug 26, 2018

I got the Solution,

import firebase from 'react-native-firebase';
 
import type {RemoteMessage} from 'react-native-firebase';

export default async (message: RemoteMessage) => {
 const GetData=firebase.firestore().collection(`Messages`).doc(`${message.data.Doc_Id}`).get({source:'server'})
    return Promise.resolve(GetData);
}

@tanveerbyn
Copy link

can you provide full code of that example.... coz I didn't got any solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants