iOS开发——网络编程Swift篇&(四)异步Get方式
异步Get方式
// MARK: - 异步Get方式 func asynchronousGet() { //创建NSURL对象 var url:NSURL! = NSURL(string: "http://m.weather.com.cn/data/101010100.html") //创建请求对象 var urlRequest : NSURLRequest = NSURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy, timeoutInterval: ) //连接服务器 var connection = NSURLConnection(request: urlRequest, delegate: self) } // MARK: - NSURLConnectionDelegate : NSObjectProtocol { func connection(connection: NSURLConnection, didFailWithError error: NSError) { //请求失败 } func connectionShouldUseCredentialStorage(connection: NSURLConnection) -> Bool { //连接应使用证书存储 return true } func connection(connection: NSURLConnection, willSendRequestForAuthenticationChallenge challenge: NSURLAuthenticationChallenge) { //发送请求验证 } func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool { //可以验证的保护空间 return true } func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge) { //获得认证 } func connection(connection: NSURLConnection, didCancelAuthenticationChallenge challenge: NSURLAuthenticationChallenge) { //取消认证 }
iOS开发——网络编程Swift篇&(四)异步Get方式的更多相关文章
- iOS开发——网络编程Swift篇&(六)异步Post方式
异步Post方式 // MARK: - 异步Post方式 func asynchronousPost() { //创建NSURL对象 var url:NSURL! = NSURL(string: &q ...
- iOS开发——网络编程Swift篇&Alamofire详解
Alamofire详解 预览图 Swift Alamofire 简介 Alamofire是 Swift 语言的 HTTP 网络开发工具包,相当于Swift实现AFNetworking版本. 当然,AF ...
- iOS开发——网络编程Swift篇&(八)SwiftyJSON详解
SwiftyJSON详解 最近看了一些网络请求的例子,发现Swift在解析JSON数据时特别别扭,总是要写一大堆的downcast(as?)和可选(Optional),看?号都看花了.随后发现了这个库 ...
- iOS开发——网络编程Swift篇&(二)同/异&步请求
同/异&步请求 同步: // MARK: - 同步请求 func httpSynchronousRequest() { //创建NSURL对象 var url:NSURL! = NSURL(s ...
- iOS开发——网络编程Swift篇&(七)NSURLSession详解
NSURLSession详解 // MARK: - /* 使用NSURLSessionDataTask加载数据 */ func sessionLoadData() { //创建NSURL对象 var ...
- iOS开发——网络编程Swift篇&(一)网络监测
网络监测 enum ReachabilityType { case WWAN, WiFi, NotConnected } public class Reachability { /** :see: O ...
- iOS开发——网络编程Swift篇&(五)同步Post方式
同步Post方式 // MARK: - 同步Post方式 func synchronousPost() { //创建NSURL对象 var url:NSURL! = NSURL(string: &qu ...
- iOS开发——网络编程Swift篇&(三)同步Get方式
同步Get方式 // MARK: - 同步Get方式 func synchronousGet() { //创建NSURL对象 var url:NSURL! = NSURL(string: " ...
- iOS开发——动画编程Swift篇&(四)CABasicAnimation动画
CABasicAnimation动画 //CABasicAnimation-不透明度 @IBAction func cabOpacity() { let animation = CABasicAnim ...
随机推荐
- 大连网络赛 1006 Football Games
//大连网络赛 1006 // 吐槽:数据比较水.下面代码可以AC // 但是正解好像是:排序后,前i项的和大于等于i*(i-1) #include <bits/stdc++.h> usi ...
- OpenStack Cinder组件支持的块存储设备表
摘自恒天云官网:http://www.hengtianyun.com/download-show-id-18.html OpenStack的Cinder组件底层可以连接多种存储设备和方案,每一个Ope ...
- grep in linux
1.作用linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来.grep全称是Global Regular Expression Print,表示全局正 ...
- Entity Framework Power Tools
http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d
- 有趣的Node爬虫,数据导出成Excel
最近一直没更新了诶,因为学习Backbone好头痛,别问我为什么不继续AngularJs~因为2.0要出来了啊,妈蛋!好,言归正传,最近帮我的好基友扒数据,他说要一些股票债券的数据.我一听,那不就是要 ...
- JavaScript快排与原生sort的测试
今天工作室断网!果断回宿舍,不然各种资料都没有.(他说将来会找到!)不好意思,又哼起来了.进入主题,大家都知道,快排是各种排序算法中,最高效的也是应用最广的,还有更重要的一点,面试特别爱考的! 其实大 ...
- urllib2中自定义opener
正常用Python抓取网页信息,需要用到urllib2,调用urllib2.urlopen(url),可以获得response 反馈信息,再用response.read()即可获得页面的源码. 最简单 ...
- JSF 2 multiple select dropdown box example
In JSF, <h:selectManyMenu /> tag is used to render a multiple select dropdown box – HTML selec ...
- Spring MVC SimpleUrlHandlerMapping example
In Spring MVC application, the SimpleUrlHandlerMapping is the most flexible handler mapping class, w ...
- Spring MVC ControllerClassNameHandlerMapping example
handler mapping是把url跟控制器关联起来. In Spring MVC, ControllerClassNameHandlerMapping use convention to map ...