【发布时间】:2017-11-15 05:19:41
【问题描述】:
所以我有这个代码
func requestMSG(){
if uID != nil {
let parameter: Parameters = [
"id" : self.uID!
]
Alamofire.request("http://front\(randomServer).omegle.com/events", method: .post, parameters: parameter).responseData { (response) in
if let check = response.error{
print(check.localizedDescription)
}
}
Alamofire.request("http://front\(randomServer).omegle.com/events",method: .post , parameters: parameter).responseJSON { (response) in
if response.result.value != nil {
print("This is response: \(response)")
if let result = response.result.value {
let JSON = result as? [[String]]
if JSON?.count == 1{
if JSON?[0].count == 2{
print(JSON?[0][1] as Any)
self.chatLog.append((JSON?[0][1])!)
self.chatTable.reloadData()
}
}
}
}
}
}
}
稍后,我触发了一个“定时器”,它从“/event”请求一些信息。 响应看起来像这样
This is response: SUCCESS: <null>
This is response: SUCCESS: <null>
This is response: SUCCESS: <null>
This is response: SUCCESS: <null>
This is response: SUCCESS: (
"hiii there"
Optional("hiii there")
This is response: SUCCESS: <null>
This is response: SUCCESS: <null>
每秒请求 1 次。但是……
我只想在服务器有东西要显示时才向服务器发送请求,在这个例子中,是来自用户的消息。
我该怎么做?
【问题讨论】: