简体   繁体   中英

Get react native client, firebase token

I'm a react-native newbee, trying to build an app which will receive notifications from an app server. The flow will be like this: App server -> FCM Cloud -> App client(android or ios).

I've started with [1] and I'm trying to generate and get a device token to be sent to the app server for identification. However I'm getting an error:

import * as firebase from 'firebase';

const defaultAppConfig = {
   ...
};

var defaultApp = firebase.initializeApp(defaultAppConfig);
var defaultMessaging = firebase.messaging();  // -> here, messaging not found

Can someone help me figure out how to get a reference to the cloud messaging object, and get that token, eventually?

[1] https://facebook.github.io/react-native/docs/getting-started.html

Firebase SDK is made for the web so some functionalities won't work as you expect them to work, also to use push notifications in your project you'll need to write some native code to ask for permission in the user device and import firebase messaging in Android and almost the same (but with a little bit more configuration, notifications certificate from Apple and of course a paid developer account) to run it on iOS.

I'll recommend you to use react-native-firebase as they have a lot of very well writen documentations that will help you configure everything.

Hope this helps! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM