【发布时间】:2017-03-29 07:21:59
【问题描述】:
我已将 Pubnub Javascript sdk-v4 与我的 react native 项目集成。 并已使用 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>
)
}
【问题讨论】:
-
您能否使用同一文件中的完整代码更新您的代码?
-
@CraigConover,你很高兴来到这里。我更新了代码段。我无法将所有代码文件放在这里。这是代码文件的流程,这是导航的第一页。 (用户登录后的主页)。
-
嗨@CraigConover,有什么更新吗?
-
我们需要更多细节。您可以将带有重现步骤和数据的完整压缩项目提交到 support@pubnub.com 吗?解决后我们可以在此处发布答案。
-
将通知方法与 Pubnub 集成的方式存在问题。然后我尝试了这个(pubnub.com/docs/react-native-javascript/mobile-gateway),它成功了。感谢@CraigConover 的帮助。
标签: iphone react-native push-notification pubnub react-native-ios