Quickblox用户在线状态IOS

Quickblox用户在线状态IOS,ios,chat,quickblox,Ios,Chat,Quickblox,我一直在使用IOS版quickblox sdk,我有一个关于用户在线状态的查询 下面是推荐的代码 QBUUser *user = ...; NSInteger currentTimeInterval = [[NSDate date] timeIntervalSince1970]; NSInteger userLastRequestAtTimeInterval = [[user lastRequestAt] timeIntervalSince1970]; // if user didn't

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

下面是推荐的代码

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秒我都想知道用户是否在线或是否有其他更好的方法?

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

这是我了解用户存在的自定义函数。我设置了一个计时器,每10秒运行一次

 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)
    }
func更新(){
让currentTimeInterval:Int=Int(NSDate().timeIntervalSince1970)
var userlastrew=Int()
让rid=UInt(dialog.recipientID)
var=Int()
userWithID(rid,successBlock:{(响应:QBResponse,用户:QBUUser?)->Void in
userlastrew=Int((用户?.lastRequestAt?.timeIntervalSince1970)!)
差异=当前时间间隔-userlastrew
如果差异大于120{
设(d,h,m)=自身秒到小时分钟秒(不同)
var txt=String()
如果(d 60&&h>1){
txt=“上次联机\(h)小时前”
}
如果(m>=60&&h==1){
txt=“上次联机\(h)小时前”
}
如果(m<60&&h<1){
txt=“上次联机\(m)分钟前”
}
如果(m<60&&h==1){
txt=“上次联机\(h)小时前”
}
如果(m<60&&h>1){
txt=“上次联机\(h)小时前”
}
}否则{
如果(d>1){
txt=“上次联机\(d)天前”
}否则{
txt=“上次联机\(d)天前”
}
}
//用户处于脱机状态
}否则{
//用户在线
}
},errorBlock:{(响应:QBResponse)->中的Void
//处理错误
})
}
func secondstohoursminuteseconds(秒:Int)->(Int,Int,Int){
返回(秒/86400,秒/3600,(秒%3600)/60)
}