2017-06-21 119 views
0

我試圖通過令牌ID從Firebase控制檯向我的ios設備發送推送通知。我正在使用react-native-firebase來允許應用根據通知事件執行操作。我跟着指示,將SDK整合,併成立了APNS證書等:無法使用react-native-firebase從Firebase控制檯發送推送通知

http://invertase.io/react-native-firebase/#/installation-ios

firebase.js配置文件看起來是這樣的:

import RNFirebase from 'react-native-firebase'; 

const configurationOptions = { 
    debug: true 
}; 

const firebase = RNFirebase.initializeApp(configurationOptions); 

export default firebase; 

我的主要陣營組成部分看起來是這樣的:

import React, { Component } from 'react' 
import { 
    Text, 
    View, 
    Alert, 
    Platform 
} from 'react-native' 
import firebase from './firebase' 

export default class extends Component { 

    constructor(props) { 
    super(props) 
    this.state = { 
     token: '' 
    } 
    } 

    componentDidMount() { 
    firebase.messaging().getToken() 
     .then((token) => { 
      this.setState({ token }) 
      console.log('token: ', token) 
     }) 

    firebase.messaging().getInitialNotification() 
     .then((notification) => { 
      console.log('Notification which opened the app: ', notification) 
     }) 

    firebase.messaging().onMessage((message) => { 
     console.log('messaging', message) 
    }) 

    firebase.messaging().onTokenRefresh((token) => { 
     console.log('Refreshed FCM token: ', token) 
    }) 
    } 

    render() { 
    return (
     <View style={{ marginTop: 22 }}> 
      <Text>{this.state.token}</Text> 
     </View> 
    ) 
    } 

}

我在組件裝入後成功獲取令牌,然後在Firebase控制檯中使用該令牌發送通知,但未收到通知。我正在使用真實設備,而不是iPhone。我正在使用啓用了推送通知的開發資源調配配置文件,併成功啓用了移除通知背景權利以及已上傳到Firebase控制檯的相應開發APN證書。

爲什麼我沒有收到設備上的通知?

回答

1

好吧,看起來它只是忽略了遠程通知,因爲我沒有向用戶請求權限。只需要通過SDK來完成:

componentDidMount() { 
    firebase.messaging().requestPermissions() 
    firebase.messageing().getToken().then... 
相關問題