码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发——网络编程Swift篇&(四)异步Get方式

时间:2015-06-07 23:31:31      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

异步Get方式

 

 1     // MARK: - 异步Get方式
 2     func asynchronousGet()
 3     {
 4         //创建NSURL对象
 5         var url:NSURL! = NSURL(string: "http://m.weather.com.cn/data/101010100.html")
 6         
 7         //创建请求对象
 8         var urlRequest : NSURLRequest = NSURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy, timeoutInterval: 10)
 9         
10         //连接服务器
11         var connection = NSURLConnection(request: urlRequest, delegate: self)
12     }
13     
14     
15     // MARK: - NSURLConnectionDelegate : NSObjectProtocol {
16     func connection(connection: NSURLConnection, didFailWithError error: NSError)
17     {
18         //请求失败
19     }
20     func connectionShouldUseCredentialStorage(connection: NSURLConnection) -> Bool
21     {
22         //连接应使用证书存储
23         return true
24     }
25     func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: NSURLAuthenticationChallenge)
26     {
27         //发送请求验证
28     }
29     func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool
30     {
31         //可以验证的保护空间
32         return true
33     }
34     func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge)
35     {
36         //获得认证
37     }
38     func connection(connection: NSURLConnection, didCancelAuthenticationChallenge challenge: NSURLAuthenticationChallenge)
39     {
40         //取消认证
41     }

 

 

iOS开发——网络编程Swift篇&(四)异步Get方式

标签:

原文地址:http://www.cnblogs.com/iCocos/p/4559623.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!