gpt4 book ai didi

android - 后台应用程序在 Titanium 中不接收来自 pubnub for android 的消息

转载 作者:搜寻专家 更新时间:2023-11-01 09:26:03 27 4
gpt4 key购买 nike

我正在使用 pubnub 从 android 服务器推送消息。当应用程序处于前台时,我收到消息。但是如果应用程序在后台模式或锁定模式下处于非 Activity 状态,我没有收到消息。如果应用程序在后台或不在最近的应用程序托盘中,我如何获取 pubnub 消息?请帮帮我。谢谢。

var pubnub = new PubNub({
subscribeKey : 'sub-key',
publishKey : 'pub-key'
});

pubnub.addListener({
status : function(st) {
if (st.category === "PNConnectedCategory") {

}
},
message : function(m) {

var pushStatus = m.message;
console.log("Show Notification");

},
presence : function(ps) {
console.log(ps);
}
});

pubnub.subscribe({
channels : ['Channel']
});

最佳答案

PubNub Android 后台用例

在后台时您没有连接。过去可能只是 run your app in a background service that never gets destroyed使用一些带有唤醒锁的额外配置和设备所有者的许可,但我相信这对于非 native 应用程序是不可能的(可能使用 React-Native 但可能不是 Titanium,但我不确定)。

典型的解决方案是在应用处于后台或根本未运行(应用已被用户或系统强制终止)时使用移动推送通知(FCM,以前称为 GCM)。你可以provide an FCM payload (and APNS for iOS clients) when you publish a message .

请参阅 PubNub Titanium SDK Mobile Push Notifications 的完整文档.每个 SDK 都有相同的部分,供需要其他语言/平台的任何人使用。

关于android - 后台应用程序在 Titanium 中不接收来自 pubnub for android 的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50600997/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com