我已将 Pubnub Javascript sdk-v4 与我的 React Native 项目集成。 并已使用https://github.com/zo0r/react-native-push-notification用于 react native 推送通知。在两个模拟器(Android 和 iOS)中,当应用程序在后台运行时(即使应用程序已关闭),也会显示通知横幅。但是,在真实设备上测试时,不会显示通知横幅。通知仅显示在通知栏中(从屏幕顶部滚动时)。有什么建议吗?
代码段如下。
.
.
var PushNotification = require('react-native-push-notification');
var serviceCall = require('../../actions/serviceCall');
import PushController from '../../actions/pushController'
var PubNub = require('pubnub');
.
.
class SearchBar extends Component {
constructor(props) {
super(props);
this.state = {
...
...
};
this.constructor.childContextTypes = {
theme: React.PropTypes.object,
}
}
componentDidMount(){
var pubnub = new PubNub({
publishKey : 'pub-c-xxxxxx',
subscribeKey : 'sub-c-xxxxxx'
})
var notifyListener ={
message: function(message) {
console.warn(JSON.stringify(message));
PushNotification.localNotification({
message: message.message.text, // (required)
});
}
}
pubnub.addListener(notifyListener);
pubnub.subscribe({
channels: ['Channel-xxxxxxx']
});
}
return (
<Container>
<View theme={theme}>
<PushController/>
.
.
.
</View>
</Container>
)
}
最佳答案
我必须更改集成方法,此链接成功。
链接:https://www.pubnub.com/docs/react-native-javascript/mobile-gateway
关于iphone - Pubnub + React Native - iOS 真实设备上没有横幅通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43086932/