nsurlsession

Using NSURLSession from a Swift command line program

 ̄綄美尐妖づ 提交于 2019-12-17 17:44:22
问题 I'm trying to test a little proof-of-concept command line app prior to integrating it into a larger app. What I'm trying to do is download some data using NSURLSession using this example. However it appears that if I use the examples given in a simple OS X command line app then the app exits prior to the data being retrieved. How can I download data from a stand-alone command line app using NSURLSession? What I've read about is using NSRunLoop however I've not yet found a clear example in

NSURLConnection deprecated in iOS9

杀马特。学长 韩版系。学妹 提交于 2019-12-17 15:44:28
问题 I want to download a file with a NSURLRequest and save it but in the line with the NSData * data = ... happens an error. NSURL *Urlstring = [NSURL URLWithString:@"http://yourdomain.com/yourfile.pdf"]; NSURLRequest *request = [NSURLRequest requestWithURL: Urlstring]; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];

URLresponse is not retrieved after storing in cache using storeCachedResponse

◇◆丶佛笑我妖孽 提交于 2019-12-17 14:12:16
问题 Goal I'm trying to inject data/response from URLRequest into another URLRequest in my cache. Setup This is just a sample code. It's ready to be dumped into a project. What I'm trying to do is use the response + data retrieved from my landscapeURLString network request...store into my session's cache for my lizardURLString request. import UIKit class ViewController: UIViewController { lazy var defaultSession : URLSession = { let urlCache = URLCache(memoryCapacity: 500 * 1024 * 1024,

How To Download Multiple Files Sequentially using NSURLSession downloadTask in Swift

落爺英雄遲暮 提交于 2019-12-17 04:53:19
问题 I have an app that has to download multiple large files. I want it to download each file one by one sequentially instead of concurrently. When it runs concurrently the app gets overloaded and crashes. So. Im trying to wrap a downloadTaskWithURL inside a NSBlockOperation and then setting the maxConcurrentOperationCount = 1 on the queue. I wrote this code below but it didnt work since both files get downloaded concurrently. import UIKit class ViewController: UIViewController,

How To Download Multiple Files Sequentially using NSURLSession downloadTask in Swift

不羁岁月 提交于 2019-12-17 04:53:03
问题 I have an app that has to download multiple large files. I want it to download each file one by one sequentially instead of concurrently. When it runs concurrently the app gets overloaded and crashes. So. Im trying to wrap a downloadTaskWithURL inside a NSBlockOperation and then setting the maxConcurrentOperationCount = 1 on the queue. I wrote this code below but it didnt work since both files get downloaded concurrently. import UIKit class ViewController: UIViewController,

NSURLSession with NSBlockOperation and queues

我的梦境 提交于 2019-12-17 02:27:16
问题 I have an app that currently uses NSURLConnection for the vast majority of its networking. I would like to move to NSURLSession because Apple tells me that is the way to go. My app just uses the synchronous version of NSURLConnection by way of the + (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error class method. I do this within a NSBlockOperation running on an NSOperationQueue so I am not needlessly blocking the main

Swift: How do I return a value within an asynchronous urlsession function?

♀尐吖头ヾ 提交于 2019-12-17 02:24:32
问题 As you can see, I'm receiving a JSON file, parsing it using SwiftyJSON, and trying to return totalTime, but it won't let me. How do I do this? func googleDuration(origin: String, destination: String) -> Int{ // do calculations origin and destiantion with google distance matrix api let originFix = origin.stringByReplacingOccurrencesOfString(" ", withString: "+", options: NSStringCompareOptions.LiteralSearch, range: nil); let destinationFix = destination.stringByReplacingOccurrencesOfString(" "

iOS 编程:NSURLSession

我的未来我决定 提交于 2019-12-16 10:31:44
定义:描述 Foundation 框架类在标准的网络传输协议下,用 URLs 连接因特网并与服务器交互的一整套体系。 支持的传输协议: File Transfer Protocol ( ftp:// ) Hypertext Transfer Protocol ( http:// ) Hypertext Transfer Protocol with encryption ( https:// ) Local file URLs ( file:/// ) Data URLs ( data:// ) 结构图 网络系统模块 5个模块:代理支持、身份验证和凭据、cookie 存储、配置管理和缓存管理。 Cookie,有时也用其复数形式 Cookies ,指某些网站为了辨别用户身份、进行 session 跟踪而储存在用户本地终端上的数据(通常经过加密)。 NSURLSessionTask NSURLSessionDelegate 委托协议 Session 会话的概念 Session中任务的行为取决于三个方面: Session 的类型(取决于创建的配置对象类型); task 任务的类型; task 任务被创建时,app 是否处于前台状态? Session 的类型 默认会话(Default session) :与其他用于下载URL的 Foundation 方法类似。

AFNetworking 2 and background tasks

我只是一个虾纸丫 提交于 2019-12-14 02:39:51
问题 I have a question about AFNetworking 2 and background downloads/uploads thanks to the new iOS7 NSURLSession background requests Is this automatically handled by my AFHTTPRequestOperationManager ? Does it automatically set my requests'session to background mode? I saw that the AFURLSessionManager Has a setDidFinishEventsForBackgroundURLSessionBlock Method but I wonder if everything is automatic? If my app is killed or suspended, will requests keep on going? How can I get a callback when my app

NSURLSession 3xx redirects and completion handlers

。_饼干妹妹 提交于 2019-12-14 01:26:24
问题 I have a dataTask + completionHandler approach to downloading data from a web server. So far I have implemented this: let task = session.dataTaskWithURL(url, completionHandler: { (pageData,response,error) in ... ... let code = urlHttpResponse.statusCode switch code { case 200: self.fetchedPages.updateValue(pageData, forKey: pageNumber) case 404: self.fetchedPages.updateValue(nil, forKey: pageNumber) //No data exists for that page default: self.fetchedPages.updateValue(nil, forKey: pageNumber)