Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 在React Native中,当用户安装应用程序但未登录或注册时,如何发送通知?_Firebase_React Native_Google Cloud Firestore_Push Notification - Fatal编程技术网

Firebase 在React Native中,当用户安装应用程序但未登录或注册时,如何发送通知?

Firebase 在React Native中,当用户安装应用程序但未登录或注册时,如何发送通知?,firebase,react-native,google-cloud-firestore,push-notification,Firebase,React Native,Google Cloud Firestore,Push Notification,我正在用React Native为iOS和Android编写一个项目,我想在用户只安装应用程序但3天后不登录或注册时自动发送通知。我在项目中使用firebase云数据。是否可以对firebase或firebase进行过度编码?使用firebase,您甚至可以在设备未登录的情况下获取FCM令牌。不过,您需要获得他们的许可才能接收通知 import React, { Component } from "react"; import { Text, View } from &quo

我正在用React Native为iOS和Android编写一个项目,我想在用户只安装应用程序但3天后不登录或注册时自动发送通知。我在项目中使用firebase云数据。是否可以对firebase或firebase进行过度编码?

使用firebase,您甚至可以在设备未登录的情况下获取FCM令牌。不过,您需要获得他们的许可才能接收通知

import React, { Component } from "react";
import { Text, View } from "react-native";
import firebase from "react-native-firebase";

export default class componentName extends Component {
  async componentDidMount() {
    this.checkPermission();
  }
  //1
  async checkPermission() {
    firebase
      .messaging()
      .hasPermission()
      .then((enabled) => {
        if (enabled) {
          this.getToken();
        } else {
          this.requestPermission();
        }
      });
  }

  //2
  async requestPermission() {
    firebase
      .messaging()
      .requestPermission()
      .then(() => {
        this.getToken();
      })
      .catch((error) => {});
  }

  //3
  async getToken() {
    fcmToken = await firebase.messaging().getToken();
    if (fcmToken) {
      // 
      // 
      // 
      // 
      // 
      //     Call your API here
      // 
      // 
      // 
      // 
      // 
      // 
    }
  }
  render() {
    return (
      <View>
        <Text> Your APP </Text>
      </View>
    );
  }
}


你的问题没有足够的意义。你在说什么样的通知?发送事件的某种分析通知,向用户发送推送通知?你在这个问题上已经做了哪些研究?StackOverflow是在您已经尝试过之后使用的,因此请向我们展示您尝试过但不起作用的内容-即使这只是意味着我在internet上查找了“x”,但找不到任何内容。因为您使用了推送通知标签,我猜您希望使用推送通知来定位这些特定用户。您的应用程序是否设计为用户无需登录或创建帐户即可使用?无论哪种方式,都有可能做到你所要求的,但我认为你不太可能真正接触到很多人。在首次打开时请求通知的应用程序通常会被拒绝权限。我建议寻找另一种向符合这些标准的人发送消息的方式,例如完全由应用程序控制的本地通知。我研究了很多关于它的话题。但大多数解决方案都是在您登录或在应用程序中联机时发送通知。但我想发送通知,好像我们想念你,或者你为什么不登录我们的应用程序,当用户下载应用程序但一次也没打开时。其中一个解决方案是设置一个警报,每天启动一次短时间运行的服务。该服务所做的只是检查类似于上次使用时间的共享首选项。如果时间超过3天,则服务将发送通知。无论哪种方式,服务都会退出。或者,您的应用程序可以在每次运行时提交一个警报,该警报被定义为在3天内触发,并被定义为用相同ID替换任何预先存在的警报。该警报将被定义为打开发送通知的短期运行服务。在react native中该解决方案可行吗。我不知道如何设置每天启动一次短时间运行服务的警报。谢谢:这个解决方案可能有效。我会尝试一下,并向您发送反馈,无论它是否有效。