如何使用Swift 4在pubnub中显示在线离线用户状态?

时间:2019-05-23 14:19:16

标签: ios swift pubnub

client.setState(["is_online": true,"user_id":uuid], forUUID: userId as! String, onChannel: "channelName") { (status) in
    if !status.isError {
      print(status)
    } 
}

1 个答案:

答案 0 :(得分:0)

可以使用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()
         */
    }
})