我已将Pubnub Javascript sdk-v4与我的反应原生项目集成在一起。 并使用https://github.com/zo0r/react-native-push-notification进行反应本机推送通知。在两个模拟器(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>
)
}
答案 0 :(得分:3)
我不得不改变整合方法,这个链接很成功。
链接:https://www.pubnub.com/docs/react-native-javascript/mobile-gateway