【问题标题】:How to show online offline user status in pubnub using swift 4?如何使用 swift 4 在 pubnub 中显示在线离线用户状态?
【发布时间】:2019-05-23 14:19:16
【问题描述】:
client.setState(["is_online": true,"user_id":uuid], forUUID: userId as! String, onChannel: "channelName") { (status) in
    if !status.isError {
      print(status)
    } 
}

【问题讨论】:

  • 请描述您的问题。您是否收到错误消息?
  • 如果您在使用 PubNub SDK 时遇到问题,请通过PubNub Support 提交支持票,而不是在这里发布含糊的问题。我们将回答您的问题。

标签: ios swift pubnub


【解决方案1】:

可以使用PubNub Presence feature 实现用户在线功能。转到您的 PubNub Admin Dashboard 并为您的 API 密钥启用在线状态功能。

现在在客户端,您可以使用whereNowUUID 方法检查哪些用户在线,该方法在Swift PubNub Presence Documentation 中有详细描述

self.client.whereNowUUID(self.client.uuid(), withCompletion: { (result, status) in

    if status == nil {

        // Handle downloaded presence 'where now' information using: result.data.channels
    }
    else {

        /**
         Handle presence audit error. Check 'category' property
         to find out possible reason because of which request did fail.
         Review 'errorData' property (which has PNErrorData data type) of status
         object to get additional information about issue.

         Request can be resent using: status.retry()
         */
    }
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多