我正在尝试使用react-native-firebase框架将Firebase集成到我的expo应用firebase程序中,当涉及到本机应用时,它比常规软件包有几个优势.
但是,我遇到了困难,因为说明我必须添加GoogleService-Info.plist到ios/[YOUR APP NAME]/GoogleService-Info.plist,并且expo应用程序没有我理解的ios文件夹.
我差点搞砸了还是有解决方案?
我正在尝试使用Firebase(Cloud Firestore)作为本机应用程序,以存储我的JSON对象。
我见过人们在他们的应用程序中使用Firebase (npm install firebase),而其他人则使用react-native-firebase。
大多数博客都说Firebase本身是用于Web的,因此它们的本机响应支持是“无/少”。而其他一些博客和firebase官方博客则说Firebase支持本地本机。
我不确定为我的本机项目选择哪个库,它们之间有什么区别。
firebase react-native google-cloud-firestore react-native-firebase
我正在使用react-native-firebaseon React nativein开发通知功能Android。
大部分功能(如前台后台远程通知、显示本地通知)都实现的很好,但有一个问题我没有解决。
正如我上面所说,在前台和后台接收通知运行良好。当设备的屏幕关闭(锁定模式或打瞌睡模式)时,通过振动和声音很好地接收通知,但屏幕不亮。我已经在模拟器(带有 Google play 的 Nexus 5X)、LG G Flex2、三星 Galaxy S8 上进行了测试。
当通知到达 Android 时唤醒设备(打开屏幕)
收到通知时,声音和振动正常,但屏幕关闭。
我还没有在 iOS 上测试过。这是我的配置。
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Run Code Online (Sandbox Code Playgroud)
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.1'
}
Run Code Online (Sandbox Code Playgroud)
compileSdkVersion 26
minSdkVersion 16
targetSdkVersion 26
Run Code Online (Sandbox Code Playgroud)
"react": "^16.3.0-alpha.1",
"react-native": "0.54.3",
Run Code Online (Sandbox Code Playgroud)
"react-native-firebase": "^4.2.0",
Run Code Online (Sandbox Code Playgroud)
async configureNotifications() {
const enabled = await firebase.messaging().hasPermission();
if (enabled) {
this.listenNotification();
} else {
try {
await firebase.messaging().requestPermission();
this.listenNotification();
} catch (e) { …Run Code Online (Sandbox Code Playgroud) 我在我的反应原生项目[android平台]中使用了react-native-firebase来显示应用程序通知.使用此库,我可以在应用程序处于前台/后台/关闭状态时显示通知.
根据react本机firebase文档,当通知点击打开应用程序时,应触发onNotificationOpened.但是,在我的情况下不会发生这种情况,从不调用onNotificationOpened方法,并且getInitialNotification方法始终获取空值.
我也使用react-native-splash-screen库来显示启动画面.
这是来自App.js >> componentDidMount()的代码
firebase.messaging().requestPermission()
.then(() => {
const myAppChannel = new firebase.notifications.Android.Channel('my-channel',
'my Channel', firebase.notifications.Android.Importance.Max)
.setDescription('my channel');
firebase.notifications().android.createChannel(myAppChannel);
this.messageListener = firebase.messaging().onMessage((message) => {
const {title, body} = message.data;
const notificationDisplay = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle(title)
.setBody(body)
.setData({
key1: 'value1',
key2: 'value2',
}).setSubtitle('notification')
.setSound('default');
notificationDisplay
.android.setChannelId('my-channel')
.android.setSmallIcon('ic_launcher')
.android.setAutoCancel(true).android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications().displayNotification(notificationDisplay);
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
//never gets called
console.log('onNotificationOpened was triggered on notification …Run Code Online (Sandbox Code Playgroud) 我正在使用react-native-fbsdk: 0.8.0, react-native-firebase: ^5.2.2, react-native: ^0.57.4Facebook 测试用户帐户。
这发生的太突然了。一旦我从 firebase 注销并尝试使用 Facebook 再次登录。
错误:提供的身份验证凭据格式错误或已过期。[来自 facebook.com 的 USER_INFO 远程站点 5XX]。
我试过 AccessToken.refreshCurrentAccessTokenAsync()。但是给我错误:无法刷新访问令牌。
Facebook 令牌将在 60 天后过期。查了一下token过期日期是2019年4月29日,修改test用户账号密码,重新登录,还是一样。
在 facebook 或 firebase 设置中有什么我需要做的吗?
const result = await LoginManager.logInWithReadPermissions(["public_profile","email"]);
if (result.isCancelled) {
this.setState({isLoading : false});
Alert.alert('Error','Login cancelled. Please try again');
} else {
try{
await AccessToken.refreshCurrentAccessTokenAsync();
}catch(err){
this.setState({isLoading : false});
console.log('ereee',err);
}
const data = await AccessToken.getCurrentAccessToken();
var credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken);
console.log(data.accessToken);
//here I get expired date is 2019 April 29
console.log(moment(data.expirationTime).toDate());
firebase.auth().signInWithCredential(credential) …Run Code Online (Sandbox Code Playgroud) 在react-native-firebase v6 中,我无法setBackgroundMessageHandler在我的应用程序中工作。收到通知很好,但不执行处理程序。
我已经按照指南做了,但无济于事。
import { AppRegistry } from 'react-native';
import messaging from '@react-native-firebase/messaging';
import AsyncStorage from '@react-native-community/async-storage';
import App from './App';
import { name as appName } from './app.json';
AppRegistry.registerComponent(appName, () => App);
messaging().setBackgroundMessageHandler(async ({ data: { title, message } }) => {
console.log('in background');
// Save the notification locally
const notificationList = JSON.parse(await AsyncStorage.getItem('@SM_NOTIFICATIONS')) || [];
notificationList.push({ title, message, isRead: false });
await AsyncStorage.setItem('@SM_NOTIFICATIONS', JSON.stringify(notificationList));
});
Run Code Online (Sandbox Code Playgroud)
除了传入的通知之外什么也没发生。我希望代码将传入的通知保存在AsyncStorage.
我react-native-firebase在一个项目中使用v5.6。
目标:在注册流程中,我让用户输入他们的电话号码,然后我向该电话号码发送一个 OTP。我希望能够将用户输入的代码与 Firebase 发送的代码进行比较,以便能够进入注册的后续步骤。
问题:用户获取 SMS OTP 和所有内容,但phoneAuthSnapshot返回的对象firebase.auth().verifyPhoneNumber(number).on('state_changed', (phoneAuthSnapshot => {}),它没有为 firebase 发送的代码提供值,因此没有什么可以比较用户输入的代码。但是,该verificationId属性是有价值的。这是从上述方法返回的对象:
'Verification code sent', {
verificationId: 'AM5PThBmFvPRB6x_tySDSCBG-6tezCCm0Niwm2ohmtmYktNJALCkj11vpwyou3QGTg_lT4lkKme8UvMGhtDO5rfMM7U9SNq7duQ41T8TeJupuEkxWOelgUiKf_iGSjnodFv9Jee8gvHc50XeAJ3z7wj0_BRSg_gwlN6sumL1rXJQ6AdZwzvGetebXhZMb2gGVQ9J7_JZykCwREEPB-vC0lQcUVdSMBjtig',
code: null,
error: null,
state: 'sent'
}
Run Code Online (Sandbox Code Playgroud)
这是我的屏幕实现:
firebase
.firestore()
.collection('users')
.where('phoneNumber', '==', this.state.phoneNumber)
.get()
.then((querySnapshot) => {
if (querySnapshot.empty === true) {
// change status
this.setState({ status: 'Sending confirmation code...' });
// send confirmation OTP
firebase.auth().verifyPhoneNumber(this.state.phoneNumber).on(
'state_changed',
(phoneAuthSnapshot) => {
switch (phoneAuthSnapshot.state) {
case firebase.auth.PhoneAuthState.CODE_SENT:
console.log('Verification code sent', phoneAuthSnapshot);
this.setState({ status: …Run Code Online (Sandbox Code Playgroud) react-native Firebase我使用和创建了推送通知react-native-push-notification。我已经实现了所有类型的通知,例如本地通知、计划背景通知和退出通知。但当我的应用程序处于退出状态时,我已通过FCM发送了推送通知。所以我在控制台上显示了一条警告,即WARN No task Registration for key ReactNativeFirebaseMessagingHeadlessTask。那我该如何解决呢。
代码:
import React, {Fragment, useEffect} from 'react';
import {StyleSheet, View, Text, Button} from 'react-native';
import PushNotification from 'react-native-push-notification';
import messaging from '@react-native-firebase/messaging';
//1
const checkPermission = () => {
messaging()
.hasPermission()
.then((enabled) => {
if (enabled) {
getToken();
} else {
requestPermission();
}
})
.catch((error) => {
console.log('error checking permisions ' + error);
});
};
//2
const requestPermission = () => {
messaging()
.requestPermission()
.then(() …Run Code Online (Sandbox Code Playgroud) react-native firebase-cloud-messaging react-native-firebase react-native-push-notification
Firebase 编译错误[FIRAnalytics setScreenName ...]于RNFirebaseAnalytics.m
从0.61更新到react-native 0.64.2时
node_modules/react-native-firebase/ios/RNFirebase/analytics/RNFirebaseAnalytics.m:20:19:错误:选择器没有已知的类方法'setScreenName:screenClass:'
[FIRAnalytics setScreenName:screenName screenClass:screenClassOverriew];
Run Code Online (Sandbox Code Playgroud)
以下构建命令失败:CompileC/<PATH_TO_DERIVEDDATA>/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/RNFirebase.build/Objects-normal/x86_64/RNFirebaseAnalytics.o /<PROJECT_PATH>/node_modules/react-native-firebase/ios/RNFirebase/analytics/RNFirebaseAnalytics.m正常 x86_64 Objective-c com.apple.compilers.llvm.clang.1_0.compiler
本地开发人员。在过去的四年里,我一直在开发和维护一个反应原生应用程序。现在我已经不知道如何调试我的应用程序了。为了稳定性和功能要求,我正在使用react-native-reanimated和的最新版本@react-native-firebase。这两个库都对调试有限制。
react-native-reanimated使用 Turbo Modules 并使用 chrome 工具和出色的react-native-debugger.
@react-native-firebasev15.x 以上版本现在要求我们将其包含use_frameworks!在 Podfile 中,这会破坏 Flipper 调试。
如果没有这些调试选项,还剩下什么?有没有人处于同样的情况,并且有解决方案来调试他们的react-native应用程序并查看他们的redux状态?
我很感激你的帮助。
我的应用程序中的当前版本:
"@react-native-firebase/app": "15.5.0",
"react": "18.1.0",
"react-native": "0.70.5",
"react-native-reanimated": "^2.13.0",
Run Code Online (Sandbox Code Playgroud) debugging react-native react-native-firebase react-native-reanimated