首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Quickblox用户在线状态IOS

Quickblox用户在线状态IOS
EN

Stack Overflow用户
提问于 2015-09-03 13:00:40
回答 2查看 695关注 0票数 4

我一直在使用IOS版的quickblox sdk,我有一个关于用户在线状态的问题。

下面是推荐的代码。

代码语言:javascript
复制
QBUUser *user = ...;

NSInteger currentTimeInterval = [[NSDate date] timeIntervalSince1970];
NSInteger userLastRequestAtTimeInterval   = [[user lastRequestAt] timeIntervalSince1970];

// if user didn't do anything last 1 minute (60 seconds)    
if((currentTimeInterval - userLastRequestAtTimeInterval) > 60)
{ 
 // user is offline now
}

但我的疑问是,我是否需要在计时器事件中检查这一点,因为每隔5-10秒,我就想知道用户是否在线或是否有其他更好的方法?

EN

回答 2

Stack Overflow用户

发布于 2015-09-04 16:18:19

Kudi,找出用户请求的最后日期的唯一方法是使用QBUUser lastRequestAt。

票数 1
EN

Stack Overflow用户

发布于 2016-06-10 22:58:27

下面是我的自定义函数,用于了解用户的状态。我设置了一个计时器,每10秒计时一次。

代码语言:javascript
复制
 func update() {
            let currentTimeInterval: Int = Int(NSDate().timeIntervalSince1970)
            var userlastrew = Int()

            let rid = UInt(dialog.recipientID)
            var differ = Int()

            QBRequest.userWithID(rid, successBlock: { (response : QBResponse, user: QBUUser?) -> Void in
                userlastrew = Int((user?.lastRequestAt?.timeIntervalSince1970)!)
                differ = currentTimeInterval - userlastrew

                if differ > 120 {
                    let (d,h,m) = self.secondsToHoursMinutesSeconds(differ)
                    var txt = String()
                    if (d <= 0) {
                        if (m > 60 && h > 1 ) {
                            txt = "Last online \(h) hours ago"
                        }
                        if (m >= 60 && h == 1) {
                            txt =  "Last online \(h) hour ago"
                        }
                        if (m < 60 && h < 1) {
                            txt = "Last online \(m) minutes ago"
                        }
                        if (m < 60 && h == 1) {
                            txt = "Last online \(h) hour ago"
                        }
                        if (m < 60 && h > 1) {
                            txt = "Last online \(h) hours ago"
                        }
                    } else {
                        if (d > 1) {
                            txt = "Last online \(d) days ago"
                        } else {
                            txt = "Last online \(d) day ago"
                        }

                    }
                    //user is offline
                } else {
                    //user is online   
                }
                }, errorBlock: {(response: QBResponse) -> Void in
                    // Handle error
            })
        }

func secondsToHoursMinutesSeconds (seconds : Int) -> (Int, Int, Int) {
        return (seconds / 86400, seconds / 3600, (seconds % 3600) / 60)
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32367296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档