标签: react-native-firebase

当通知到达带有 react-native-firebase 的 Android 时,如何唤醒设备?

我正在使用react-native-firebaseon React nativein开发通知功能Android

大部分功能(如前台后台远程通知、显示本地通知)都实现的很好,但有一个问题我没有解决。

正如我上面所说,在前台和后台接收通知运行良好。当设备的屏幕关闭(锁定模式或打瞌睡模式)时,通过振动和声音很好地接收通知,但屏幕不亮。我已经在模拟器(带有 Google play 的 Nexus 5X)、LG G Flex2、三星 Galaxy S8 上进行了测试。

期待

当通知到达 Android 时唤醒设备(打开屏幕)

现在的情况

收到通知时,声音和振动正常,但屏幕关闭。

我还没有在 iOS 上测试过。这是我的配置。

gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Run Code Online (Sandbox Code Playgroud)

build.gradle(项目)

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)

build.gradle(应用程序)

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 版本

"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 react-native-firebase

7
推荐指数
0
解决办法
1760
查看次数

无法让 setBackgroundMessageHandler 工作

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.

android react-native react-native-firebase

7
推荐指数
1
解决办法
6149
查看次数

如何使用 Firebase 的“verifyPhoneNumber()”来确认电话 # 所有权而不使用 # 登录?

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)

firebase firebase-authentication react-native-firebase

7
推荐指数
1
解决办法
9193
查看次数

react-native-firebase:如何在注销时删除令牌?

一旦用户退出,我想停止接收应用程序的通知。我想我必须删除 react-native-firebase 生成的设备令牌,但我找不到任何功能来执行此操作。

有谁知道如何做到这一点?

react-native react-native-firebase

6
推荐指数
2
解决办法
4306
查看次数

找不到 -lRNFirebase React Native 的库

Xcode 给我一个错误:

xcode错误库未找到-RNFirebase

我正在使用 React Native Firebase,我已按照该网站上的说明进行操作,并且我似乎拥有该网站上的所有内容,但我对 Xcode 不太熟悉,因此我可以准确地看到问题。我在下面发布了更多屏幕截图:

图书馆

在此输入图像描述

Pod文件:

Podfile

编辑: 在此输入图像描述

任何帮助都感激不尽

xcode firebase react-native react-native-firebase

6
推荐指数
1
解决办法
4489
查看次数

当应用程序未在 React-Native firebase 中运行时,如何设置通知声音

我试图在应用程序未在 IOS 中运行时让通知响起。

这是我的代码。

  this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {

    // SET SYSTEM DEFAULT SOUND!
    notification.setSound("default");
    firebase.notifications().displayNotification(notification);

  });
Run Code Online (Sandbox Code Playgroud)

当应用程序处于后台或前台时(也许我可以说“应用程序正在运行”),通知会响起。

我应该使用其他监听器吗?或者我应该添加自己的铃声文件吗?

push-notification ios firebase react-native react-native-firebase

6
推荐指数
1
解决办法
9178
查看次数

onSnapshot 一段时间后似乎停止工作

我在 React Native 应用程序中对应用程序中的几组不同数据使用 firestore onSnapshot 方法,并且在大多数情况下它们似乎都工作正常。然而,一段时间后,也许应用程序进入后台并重新唤醒后,onSnapshot 方法停止更新数据。

就好像他们已经关掉了一样。有时,它们似乎在一段时间后就停止工作,而应用程序没有进入后台。

如果我再次调用这些方法,那么它们会再次开始工作,但这似乎违背了使用它们的目的,我也可以只使用普通的 get() 方法并在需要时调用它们。

当然其他人也经历过这种情况并且可以提供帮助吗?

firebase react-native google-cloud-firestore react-native-firebase

6
推荐指数
1
解决办法
1320
查看次数

在前台显示通知 React Native Firebase v6

我正在使用最新的react native版本0.62和最新版本的react-native-firebase ie v6。我能够收到通知,它在后台工作正常,但不显示在前台。

这是屏幕截图: 在此输入图像描述

这是我的代码:

checkPermission = async () => {
    const enabled = await messaging().hasPermission();
    console.log('enabled ******* ',enabled)
    if (enabled) {
      this.getFcmToken();
    } else {
      this.requestPermission();
    }
  };

  getFcmToken = async () => {
    const fcmToken = await messaging().getToken();
    if (fcmToken) {
      console.log('Your Firebase Token is:', fcmToken);
      // this.showAlert('Your Firebase Token is:', fcmToken);
    } else {
      console.log('Failed', 'No token received');
    }
  };

  requestPermission = async () => {
    try {
      await messaging().requestPermission();
      // User has authorised
    } catch …
Run Code Online (Sandbox Code Playgroud)

javascript android push-notification react-native react-native-firebase

6
推荐指数
1
解决办法
8011
查看次数

无法查看 Firebase Analytics 调试视图 React Native

我已经学习了多个教程并阅读了多个 Stackoverflow 帖子,但无论我做什么,我都无法使用 RNFireBase 在我的 iOS 应用程序的 DebugView 中显示任何内容。我真的很感激这方面的一些帮助。我已经失去了几天试图弄清楚这一点,但我不知道出了什么问题。我在模拟器和物理设备上都尝试过,但都没有运气。

我在 XCode 的控制台中收到日志消息,但在 Firebase 控制台中没有显示任何内容。以下是我在使用事件时在本地收到的消息:

反应本机

<TouchableOpacity
  onPress={() =>
    analytics().logSelectContent({
      content_type: "clothing",
      item_id: "abcd",
    })
  }
>
  <Text>Log message</Text>
</TouchableOpacity>;
Run Code Online (Sandbox Code Playgroud)

日志

2020-05-15 12:22:26.486761-0400 Example App[23464:8820959] 6.13.0 - [Firebase/Analytics][I-ACS023051] Logging event: origin, name, params: app, select_content, {
    content_type = clothing;
    ga_event_origin (_o) = app;
    ga_screen_class (_sc) = UIViewController;
    ga_screen_id (_si) = -3307323385789565728;
    item_id = abcd;
}
2020-05-15 12:22:26.487676-0400 Example App[23464:8820959] 6.13.0 - [Firebase/Analytics][I-ACS023073] Debug mode is enabled. Marking event as debug and …
Run Code Online (Sandbox Code Playgroud)

ios firebase react-native firebase-analytics react-native-firebase

6
推荐指数
1
解决办法
3676
查看次数

即使在后台,也能在 firebase 存储上响应本机上传

我实际上正在开发一个反应本机应用程序,即使用户在上传过程中关闭应用程序,我也需要上传图片/视频,当有人将应用程序置于后台时,上传会暂停/停止

所以我需要用firebase修复它,我使用Rnfirebase。谢谢你的帮助

upload background firebase react-native react-native-firebase

6
推荐指数
0
解决办法
266
查看次数