【问题标题】:How to send messges via PubNub even if the App is Killed即使应用程序被杀死,如何通过 PubNub 发送消息
【发布时间】:2016-06-05 11:15:23
【问题描述】:

我的应用程序是一个跟踪应用程序,我使用 PubNub 来实现跟踪功能,如本教程:PubNub Tracking

但我的问题是,当用户杀死应用程序时,PubNub 停止发送消息。

所以我的问题是:即使应用程序被杀死,是否仍然可以通过 PubNub 发送消息?

谢谢。

【问题讨论】:

  • 如果你的应用被杀了,那么它就死了,所以它什么也做不了
  • @Paulw11 但是当应用程序被杀死时,我仍然可以通过 coreLocation 跟踪位置,这就是为什么我认为即使应用程序被杀死也可以调用 pubNub。
  • 那么应用程序不会被杀死。如果您仍然接到您的位置代表的电话,那么您仍然可以发布消息。也许你可以展示一些代码并解释你所看到的和你所期望的

标签: ios swift pubnub


【解决方案1】:

PubNub 在 iOS 上后台运行

@Rawan 是对的 - 当您的应用在前台处于活动状态时以及当您的应用在后台运行时,您可以连接到 PubNub(这意味着您已获得 Apple 和设备所有者的许可) /user 这样做)。

但如果应用程序被终止(根本没有运行),则该应用程序与任何东西都没有连接,包括 PubNub。

Ray Wenderlich 有一个很棒的iOS background modes tutorial

【讨论】:

【解决方案2】:

您可以使用 pubnub 推送通知来做到这一点

  1. 在 pubnub 管理控制台上启用推送通知并设置您的证书
  2. 客户端:在所需通道上启用推送通知

Adding Device to Channel

PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo"
                                                              subscribeKey:@"demo"];
self.client = [PubNub clientWithConfiguration:configuration];
[self.client addPushNotificationsOnChannels:@[@"wwdc",@"google.io"]
                     withDevicePushToken:self.devicePushToken
                           andCompletion:^(PNAcknowledgmentStatus *status) {

 // Check whether request successfully completed or not.
 if (!status.isError) {

    // Handle successful push notification enabling on passed channels.
 }
 // Request processing failed.
 else {

    // Handle modification error. Check 'category' property to find out possible issue because
    // of which request did fail.
    //
    // Request can be resent using: [status retry];
 } }];
  1. 更改您的发布方法 publish to APNS devices with the PubNub

4 .重要信息格式

{    "pn_apns": {  "aps" : {

        "alert": "Game update 49ers touchdown",

“徽章”:2 }, “团队”:[“49ers”,“攻略”], “分数”:[7, 0] }, “你的信息” : { “日期”:“2014.05.20”, "foobar" : "与设备无关的数据" } }

For background message (iOS Mobile Push Gateway Tutorial)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多