[英]How to recieve response from server in swift?
func connection(connection: NSURLConnection, didReceiveResponse response: NSURLResponse) {
NSLog("Received response\(response)")
myResponseData = NSMutableData()
}
func connection(connection: NSURLConnection, didReceiveData data: NSData) {
myResponseData.appendData(data)
}
func connectionDidFinishLoading(connection: NSURLConnection) {
NSLog("\(myResponseData)");
let strData = NSString(data: myResponseData, encoding: NSUTF8StringEncoding)
print("Body: \(strData)", terminator: "")
How can we receive a response from a server and according to that set an alert message, like if the status is success we have to show an alert message 我们如何接收来自服务器的响应并根据该响应设置警报消息,例如,如果状态为成功,则我们必须显示警报消息
An easy, but not so scalable solution is: 一个简单但不那么可扩展的解决方案是:
Note that NSURConnection is deprecated in favor of NSURLSession. 请注意,不推荐使用NSURConnection,而推荐使用NSURLSession。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.