【发布时间】:2017-11-23 18:01:55
【问题描述】:
我正在尝试通过令牌 ID 从 Firebase 控制台向我的 ios 设备发送推送通知。我正在使用 react-native-firebase 来允许应用程序根据通知事件执行操作。我按照说明集成了 SDK 并设置了 APNS 证书等:
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;
我的主要 React 组件如下所示:
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 控制台的相应开发 APNs 证书。
为什么我没有在设备上收到通知?
【问题讨论】:
标签: reactjs firebase react-native firebase-cloud-messaging