nsurlsession

NSURLSession HTTP/2 memory leak

試著忘記壹切 提交于 2019-12-05 17:15:24
问题 This My Test cases, point out that when using NSURLSession with a HTTP/2 connection there is memory problem. test1: iOS 9. HTTP/2 server I use NSURLSession to upload 10M file to a HTTP/2 server, if the file uploaded completed everything is ok, But if I cancel the upload task before it's completed, the 10M will never release. test2: iOS 9. HTTPs1.1 server I test the same code with a https1.1 file server, I cancel the upload task or not, everything is ok, the memory back to normal.(10M data is

ETag and If-None-Match HTTP Headers are not working

回眸只為那壹抹淺笑 提交于 2019-12-05 16:55:41
问题 I have a file in my webserver and I am downloading that to my app everytime I access it because its possible that file content might be changed But If it is changed I would like to download that time only so bandwidth can be saved and fortunately that's what this ETag and If-None-Match header fields are for. When I make a request first time ,I retrieve the ETag from the HTTP response headers In the subsequent requests to download that file I'd attach the Etag value for If-None-Match

How do I get the data from a finished `NSURLSessionDataTask`?

我与影子孤独终老i 提交于 2019-12-05 13:42:38
I know I can use dataTaskWithURL:completionHandler: to get the data in the completionHandler block, but that blocks the delegate methods from firing, and I need the didReceiveData: method to fire, as it's how I configure my progress indicator. I'm completely at a loss how to get the downloaded data once it's complete. What's the delegate method equivalent of the completion block? didCompleteWithError doesn't seem to return any NSData . I don't have to manually piece the data together in didReceiveData , do I? That seems really lame when the completionHandler just hands it off to you. I wouldn

NSURLSession delegate methods not called

浪尽此生 提交于 2019-12-05 13:23:51
I have created a very simple app to download a text file from my web server. I have this working perfectly with NSURLConnection, but am trying to migrate over to NSURLSession instead. The issue I am having is that none of the delegate methods are being called. My server is password protected so I need to use the basic http authentication to access the file, but when the didReceiveChallenge method is never called. The line of code [getFileTask resume] seems to have no effect on anything. My setup is as follows: @interface ViewController : UIViewController <NSURLSessionDelegate,

Always getting back cached data in NSURLSessionDataTask

允我心安 提交于 2019-12-05 13:00:54
I'm facing a very strange issue when using NSURLSessionDataTask to post a JSON request to the server. The first request goes through and I receive the correct JSON response, when I do a second request I'm getting always back the old response and the server never receives the request. Even if I turn on airplane mode the NSURLSessionDataTask does work an I get back the old response again. That's the code I'm using: - (void)getJSONFromURL:(NSURL*)url identifierCode:(NSInteger)code { NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession

NSURLSession completion block not called

柔情痞子 提交于 2019-12-05 10:48:05
问题 var session = NSURLSession.sharedSession() session.dataTaskWithRequest(urlRequest, completionHandler: {(data: NSData!, response: NSURLResponse!, error: NSError!) in println(data) println(response) println(error) }) So I am making this request, and the completion block is never called. What's wrong? Also I tried a synchronous and asynchronous form of the same request with NSURLConnection and it worked perfectly. EDIT: I tried assigning a dataTask variable to the session.dataTaskWithRequest and

object-c http-get-post

霸气de小男生 提交于 2019-12-05 09:18:32
get请求 //得到session对象 NSURLSession *session = [NSURLSession sharedSession]; NSURL *url = [NSURL URLWithString:@"http://localhost:80/video"]; //创建一个任务 NSURLSessionDataTask *task = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSLog(@"----%d", data.length); }]; //开始任务 [task resume]; post请求 //创建session对象 NSURLSession *session = [NSURLSession sharedSession]; NSURL *url = [NSURL URLWithString:@"http://localhost:80/login"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; //设置request request.HTTPMethod = @"post";

iOS中的URLSession

℡╲_俬逩灬. 提交于 2019-12-05 07:41:30
URLSession NSURLSession是iOS7中新的网络接口,与NSURLConnection是并列的. 当程序在前台时, NSURLSession和 NSURLConnection大部分可以互相替代. NSURLSession支持后台网络操作,除非用户强行关闭. NSURLSession提供的功能: 1> 通过URL将数据下载到内存; 2> 通过URL将数据下载到文件系统; 3> 将数据上传到指定的URL; 4> 在后台完成上述功能. 5> 支持下载,断点续传,后台上传/下载,后台上传/下载任务跟进 对于小型数据,如用户登录,下载小图像,JSON&XML仍然使用NSURLConnection的异步或同步方法即可. NSURLSession的使用: 使用NSURLSessionConfiguration来配置NSURLSession对象 用NSURLSession对象来启动一个NSURLSessionTask对象 也可以使用系统全局的sharedSession单例来满足大多数的需求 注意: 相比较NSURLConnection的返回处理,NSURLSession提供了灵活的数据返回方式,可以使用简单的block方式来处理返回数据,也可以使用更强大的delegate. NSURLSessionConfiguration 用于定义和配置 NSURLSession对象;

NSURLSessionDownloadTaskDelegate JSON response

99封情书 提交于 2019-12-05 06:49:49
I am running a background NSURLSession session and i am trying to figure out a way to get the JSON response out of one of the NSURLDownloadTaskDelegate callbacks. I have configured my session to accept JSON responses. NSURLSessionConfiguration *backgroundSession = [NSURLSessionConfiguration backgroundSessionConfiguration:@"com.Att.Locker.BackgroundUpload"]; backgroundSession.HTTPAdditionalHeaders = @{ @"Accept":@"application/json"}; session = [NSURLSession sessionWithConfiguration:backgroundSession delegate:uploader delegateQueue:nil]; I can easily parse JSON response for

Resuming tasks using NSURLSession when app removed from background or on device reboot

自闭症网瘾萝莉.ら 提交于 2019-12-05 06:17:43
I have checked many docs but could not found solution for Resuming tasks using NSURLSession when app removed from background or on device reboot. I am dealing with amazon S3 to upload some files, In that I am able to Upload file to S3 using NSURLSessionUploadTask, when app is in foreground as well as in background. Resume task when app crashed due to any other reason while uploading and if app is not removed from background. Restart task if I reboot device while uploading and if app is not removed from background. Here is my code to achive resume fuctionality written in