无法通过应用程序发送通知以响应本机[关闭]

问题描述 投票:0回答:1
我试图在按下按钮时从应用程序向自己发送通知,但我没有在移动设备上收到任何通知。我仅收到以下我提到的意外响应,因为我是新来的我不确定如何解决此问题。我的App.js代码是

import React, { Component } from 'react' import { Text, View,Button } from 'react-native' import PushNotification from 'react-native-push-notification'; import firebase from 'react-native-firebase'; import { Header } from 'react-native/Libraries/NewAppScreen'; export default class App extends Component { getPermission = () => { firebase.messaging().requestPermission().then(() => { console.log('Has') }).catch(error => { console.log('Permission was Rejected',error) }) } async componentDidMount(){ // firebase.messaging().hasPermission().then(enable => { // if(enable){ // console.log('Has Permission') // } // else{ // this.getPermission() // } // }) let fcmToken; if(!fcmToken){ debugger fcmToken =await firebase.messaging().getToken(); console.log(fcmToken) if(fcmToken){ // await AsyncStorage.setItem('fcmToken') } } PushNotification.configure({ onNotification: function(notification) { console.log('notification',notification) } }); } sendNotifications = async () => { const FIREBASE_API_KEY ="APi_key"; const message = { registration_ids:["react native firebase id"], notification : { title : 'notification', body : "Hello There","vibrate" : 1, "sound" : 1, "show_in_underground" : true, "priority" : "high", "content_avaliable" : true } } let header = new Headers({ "Content-Type": "application/json", "Authorization" : "key="+ FIREBASE_API_KEY }) let response = await fetch("https://fcm.googleapis.com/fcm/send",{method : 'POST',header,body : JSON.stringify(message)}) console.log('here',response) } render() { return ( <View> <Text> textInComponent </Text> <Button title="Send Notification from app" onPress={() => this.sendNotifications()}></Button> </View> ) } }

当函数被调用时,我得到这个响应

type: "default" status: 401 ok: false statusText: undefined headers: Headers {map: {…}} url: "https://fcm.googleapis.com/fcm/send" _bodyInit: Blob {_data: {…}} _bodyBlob: Blob {_data: {…}} __proto__: Object

我会感谢您的帮助。
firebase react-native push-notification firebase-cloud-messaging react-native-firebase
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.