草庐IT

NSUrlSession

全部标签

ios - 如何使用 iOS 7 的 NSURLSession 接受自签名 SSL 证书

我有以下代码(快速实现):funcconnection(connection:NSURLConnection,canAuthenticateAgainstProtectionSpaceprotectionSpace:NSURLProtectionSpace)->Bool{returnprotectionSpace.authenticationMethod==NSURLAuthenticationMethodServerTrust}funcconnection(connection:NSURLConnection,didReceiveAuthenticationChallengechal

ios - NSURLSession 委托(delegate)未被调用

在下面的代码中,文件下载正常。但是,似乎没有任何委托(delegate)方法被调用,因为我没有收到任何输出。progressView也没有更新。知道为什么吗?importFoundationimportUIKitclassPodcast:PFQueryTableViewController,UINavigationControllerDelegate,MWFeedParserDelegate,UITableViewDataSource,NSURLSessionDelegate,NSURLSessionDownloadDelegate{funcdownloadEpisodeWithFee

swift - 防止 NSURLSession 缓存响应

为什么要缓存响应。它返回以前获取的响应。如果关闭网络连接,它甚至可以工作。重置iOS模拟器似乎也没有用。发出请求,然后再次使用离线互联网确实有效(缓存)。publicleturlSession:NSURLSessionpublicinit(){//...varconfiguration=NSURLSessionConfiguration.defaultSessionConfiguration()configuration.requestCachePolicy=NSURLRequestCachePolicy.ReloadIgnoringLocalCacheDataurlSession=N

macos - 从 Swift 命令行程序使用 NSURLSession

在将它集成到更大的应用程序之前,我正在尝试测试一个小的概念验证命令行应用程序。我想做的是使用NSURLSession下载一些数据thisexample.但是,如果我使用简单的OSX命令行应用程序中给出的示例,那么应用程序会在检索数据之前退出。如何使用NSURLSession从独立的命令行应用下载数据?我读到的是使用NSRunLoop但是我还没有在Swift中找到一个明确的例子,所以如果NSRunLoop实际上是要走的路,那么任何例子都将不胜感激。也欢迎使用任何其他从Swift命令行应用程序的URL下载数据的策略(无限while循环?)。 最佳答案

ios - 如何在 Swift 中使用 NSURLSession downloadTask 顺序下载多个文件

我有一个必须下载多个大文件的应用程序。我希望它按顺序而不是同时下载每个文件。当它同时运行时,应用程序会过载并崩溃。所以。我试图将downloadTaskWithURL包装在NSBlockOperation中,然后在队列上设置maxConcurrentOperationCount=1。我在下面写了这段代码,但它不起作用,因为两个文件都是同时下载的。importUIKitclassViewController:UIViewController,NSURLSessionDelegate,NSURLSessionDownloadDelegate{overridefuncviewDidLoad(

swift - 如何从 NSURLSession.sharedSession().dataTaskWithRequest 获取数据

classPostFOrData{leturl=NSURL(string:"http://210.61.209.194:8088/SmarttvWebServiceTopmsoApi/GetReadlist")varpicUrl=NSURL(string:"http://210.61.209.194:8088/SmarttvMedia/img/epi00001.png")varresponseString:NSString=""funcforData()->NSString{letrequest=NSMutableURLRequest(URL:url!)request.HTTPMeth

ios - NSURLSession“HTTP 加载失败 kCFStreamErrorDomainSSL,-9813;自签名证书

我正在尝试将我的iOS应用程序连接到当前在我网络中的本地主机上运行的HTTPSRails应用程序。我可以使用https://myIP:3000/display从我的浏览器访问该站点,也可以在命令行中使用curl请求访问该站点。我正在尝试使用以下方法从我的应用访问它:classFirstViewController:UIViewController{overridefuncviewDidLoad(){super.viewDidLoad()//leturl=NSURL(string:"https://another/Sinatra/website/feed")leturl=NSURL(st

ios - NSURLSession 数据任务请求 :completion: unrecognized selector sent to instance

当尝试创建我自己的session对象NSURLSession()并请求一个url我得到一个无法识别的选择器异常但是当我使用共享sessionNSURLSession.sharedSession()一切正常。怎么会?varurl=NSURL(string:"http:/www.google.com")ifurl!=nil{//throwsunrecognizedselectorwhendataTaskWithURLiscalledletsession=NSURLSession()session.dataTaskWithURL(url!)//worksletsharedSession=NS

http - 我能以某种方式通过 Swift 中的 NSURLSession 进行同步 HTTP 请求吗

我可以通过Swift中的NSURLSession以某种方式进行同步HTTP请求吗?我可以通过以下代码进行异步请求:ifleturl=NSURL(string:"https://2ch.hk/b/threads.json"){lettask=NSURLSession.sharedSession().dataTaskWithURL(url){(data,response,error)invarjsonError:NSError?letjsonDict=NSJSONSerialization.JSONObjectWithData(data,options:nil,error:&jsonErr

linux - IBM Swift 沙盒 : Running NSURLSession: Error running code: unknown error code 132

我正在尝试执行以下脚本:importFoundationclassTestURLSession{varsession:NSURLSession!funcrun(){session=NSURLSession.sharedSession()leturl=NSURL(string:"http://www.veenex.de/tmp/json")letrequest=NSMutableURLRequest(URL:url!)request.setValue("application/json;charset=utf-8",forHTTPHeaderField:"Content-Type")re