nsurlsession

iOS 12 URLSession breaks when HTTP request hits and suddenly app enters in background

若如初见. 提交于 2019-12-08 07:53:30
问题 For all iOS Version < 12, it is working fine. I'm testing(iOS ~> 12.x) in my app using basic URLSession and also tried with Alamofire. Test Steps: 1. Hit Any HTTP/API Call. 2. Tap on home button immediately. On coming after sometime it comes 2018-12-14 13:43:46.968901+0530 NewReader[15364:4847228] Task <519A3F27-90DA-439F-8711-B07EFA62E823>.<1> load failed with error Error Domain=NSPOSIXErrorDomain Code=53 "Software caused connection abort" UserInfo={_NSURLErrorFailingURLSessionTaskErrorKey

Moving from NSURLConnection to NSURLSession for SOAP POST in Swift

橙三吉。 提交于 2019-12-08 05:48:25
问题 I am trying to move over from NSURLConnection over to NSURLSession for a SOAP post, but seem to have issues with the NSURLSessionDataDelegate. Here is the old code in NSURLConnection that works fine: let soapMessage = "<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns1='http://tempuri.org/'><SOAP-ENV:Body><ns1:get_Countries/></SOAP-ENV:Body></SOAP-ENV:Envelope>" print("Soap Packet is \(soapMessage)") let urlString =

Post request with raw body using NSURLSession

你。 提交于 2019-12-08 05:34:22
问题 I have stuck here. Below is my code for Post request with raw body using NSURLSession. I got response = NULL and no error. NSString* stringRequest = @"https://chocudan.com/api/shops/by_ids"; NSURL* urlRequest = [NSURL URLWithString:stringRequest]; NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:urlRequest]; request.HTTPMethod = @"POST"; NSString* bodyRequest = @"563c268b84ba489c4729f149"; //I have to tried a base64 convert here but still not work. //request.HTTPBody =

'initWithRequest:delegate:' is deprecated: first deprecated in iOS 9.0 - use NSURLSession(see NSURLSession.h)

纵饮孤独 提交于 2019-12-08 02:49:27
问题 i am new in objective C and using iOS 9 Xcode 7.2 and getting this warning "'initWithRequest:delegate:' is deprecated: first deprecated in iOS 9.0 - use NSURLSession(see NSURLSession.h)" how to solve it. my code is given below. +(id)createGetConnectionWithName:(NSString*)strConnectionName_ withUrl:(NSString *)pageUrl parameterNames:(NSArray *)arrParamNames parameterValues:(NSArray *)arrParamValues delegate:(id)delegate { NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",pageUrl

NSURLSessionConfiguration timeoutIntervalForRequest doesn't seem to work with the background session

允我心安 提交于 2019-12-08 00:40:39
问题 The new timeout property of NSURLSessionConfiguration doesn't seem to work when the session is set to work in background (via backgroundSessionConfiguration call). Anybody know if that's really the case? Code snippet: NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:bgSessionConfigIdentifier]; sessionConfig.HTTPMaximumConnectionsPerHost = 1; sessionConfig.timeoutIntervalForRequest = 60; Do I need to do anything extra for the timeout to work?

NSURLSessionUploadTask get response data

折月煮酒 提交于 2019-12-07 23:03:28
问题 I have some misunderstanding in using NSURLSession framework, that's why I decided to write small app from scratch without AFFramework/Alamofire. I have an API that requires following steps to upload file: POST file data Get response (JSON) Post some json fields to api/save I have a background session with such config: let configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("myBackground") let session = NSURLSession(configuration: configuration, delegate:

iOS: Strategies for downloading very large data from web

ⅰ亾dé卋堺 提交于 2019-12-07 21:50:39
问题 I'm struggling with memory management in iOS while downloading relatively large files from the web (such as videos with 350MB size). The goal here is to download these kind of files and store it on CoreData on a Binary Data field. At the moment I'm using NSURLSession . dataTaskWithUrl and NSURLSession . dataTaskWithRequest methods to retrieve these files, but it looks like these methods don't treat problems such as memory usage, they just keep on filling the memory until it reaches its

Image(or video) posting to server in Swift

自作多情 提交于 2019-12-07 15:34:35
问题 Hi I am posting json data to server using NSURLSession in swift as below var request = NSMutableURLRequest(URL: NSURL(string: "http://mypath.com")) var session = NSURLSession.sharedSession() request.HTTPMethod = "POST" var params2 :NSDictionary = ["email":"myemail@gmail.com"] var params :NSDictionary = ["function":"forgotPassword", "parameters":params2] var err: NSError? request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &err) request.addValue("application

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

南楼画角 提交于 2019-12-07 12:22:37
问题 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

NSURLSessionDownloadTask的后台下载与断点续传

跟風遠走 提交于 2019-12-07 12:07:42
对于后台下载与断点续传相信大家肯定不会陌生,那么如果要同时实现这两种需求该怎么办呢? 使用NSURLSessionDataTask可以很轻松实现断点续传,可是有个致命的缺点就是无法进行后台下载,一点应用程序进入了后台,便会停止下载.所以无法满足我们的需求.而NSURLSessionDownloadTask是唯一可以实现后台下载的类,所以我们只能从这个类进行下手了 网上关于NSURLSessionDownloadTask的断点续传资料很多,但是很遗憾的是基本都是一模一样的CV大法.而且只有一个暂停按钮暂停后继续下载,而关于应用程序被关闭后的断点续传只字不提. 那么本篇我们就来谈谈关于应用程序随时可能被杀死的情况下,如何进行断点续传. 关于断点续传原理: 首先,如果想要进行断点续传,那么需要简单了解一下断点续传的工作机制,在HTTP请求头中,有一个Range的关键字,通过这个关键字可以告诉服务器返回哪些数据给我 比如: bytes=500-999 表示第500-第999字节 bytes=500- 表示从第500字节往后的所有字节 然后我们再根据服务器返回的数据,将得到的data数据拼接到文件后面,就可以实现断点续传了. 关于NSURLSessionDownloadTask基础 大家可以参考下这篇文章 http://my.oschina.net/iOSliuhui/blog/469276