我正在使用react-native 0.49.3版本,我的问题是如何获取 IOS和 Android的本机设备令牌我尝试使用此 link,但它不适用于我,现在我在IOS中尝试过.如何解决它可以告诉我如何配置? 我尝试了不同
Here您将找到有关通知的所有信息.
此外,您还可以使用Firebase附带的其他库,例如Google Analytics和Crash Reporting
设置库后,您可以执行以下操作:
// utils/firebase.js import RNFirebase from 'react-native-firebase'; const configurationOptions = { debug: true, promptOnMissingPlayServices: true } const firebase = RNFirebase.initializeApp(configurationOptions) export default firebase // App.js import React, { Component } from 'react'; import { Platform, View, AsyncStorage } from 'react-native'; // I am using Device info import DeviceInfo from 'react-native-device-info'; import firebase from './utils/firebase'; class App extends Component { componentDidMount = () => { var language = DeviceInfo.getDeviceLocale(); firebase.messaging().getToken().then((token) => { this._onChangeToken(token, language) }); firebase.messaging().onTokenRefresh((token) => { this._onChangeToken(token, language) }); } _onChangeToken = (token, language) => { var data = { 'device_token': token, 'device_type': Platform.OS, 'device_language': language }; this._loadDeviceInfo(data).done(); } _loadDeviceInfo = async (deviceData) => { // load the data in 'local storage'. // this value will be used by login and register components. var value = JSON.stringify(deviceData); try { await AsyncStorage.setItem(config.DEVICE_STORAGE_KEY, value); } catch (error) { console.log(error); } }; render() { ... } }
然后,您可以使用令牌和所需的所有信息调用服务器.