client.setState(["is_online": true,"user_id":uuid], forUUID: userId as! String, onChannel: "channelName") { (status) in
if !status.isError {
print(status)
}
}
答案 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()
*/
}
})