nsurlsession

Upload file with NSURLSessionUploadTask in back ground

二次信任 提交于 2019-12-06 07:32:41
问题 i am uploading multiple files using NSURLSessionUploadTask. I want to run same process in back ground and it works fine for current file. App is not suspended until current file got uploaded successfully. Now, when second files comes to upload, it not start uploading process until i again launch or app became active. Uploading is not falling in between thats good. Is there any way to start next uploading process when first finishes. Second uploading is start also in back ground but that works

How to connect to a web service using NSURLSession with Delegate methods?

情到浓时终转凉″ 提交于 2019-12-06 06:39:48
I am taking a stab at connecting to web services in iOS and I am running into a lot of problems. I found a practice web service here - http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit I have written this code out so far let soapMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" "<soap:Body>\n" "<CelsiusToFahrenheit xmlns=\"http://www.w3schools.com/webservices/\">\n" "<Celsius>50<

Swift UIImage convert as PDF

喜你入骨 提交于 2019-12-06 06:25:35
In my App have to sale UIImage from iPad Gallery and convert into PDF and save on Server side. I can select the image and send it to server side , but Backend says that pdf is empty(null data) I also see the warning/error in my console : [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled} Where am I going wrong? Thank you in advance! Code I tried //Opens gallery to select Image func clickImage() { let image = UIImagePickerController() image.delegate = self image.sourceType =

Multiple NSHTTPCookieStorage in the same app

∥☆過路亽.° 提交于 2019-12-06 06:13:36
I am writing a multi-user app using NSURLSession and I can't figure out how to have a separate cookie storage when working with multiple NSURLSession instances. I tried setting NSURLSessionConfiguration 's HTTPCookieStorage property with a NSHTTPCookieStorage that I alloc/init'ed myself but it doesn't work (cookies aren't stored, even if I call setCookie: myself) I also tried using [NSURLSessionConfiguration ephemeralSessionConfiguration] but then again, my cookies aren't stored between requests. The Set-Cookie header is present in the server's responses, and using [NSHTTPCookieStorage

NSURLSessionTask authentication challenge completionHandler and NSURLAuthenticationChallenge client

感情迁移 提交于 2019-12-06 06:08:48
问题 I am implementing a custom NSURLProtocol , and internally want to use NSURLSession with data tasks for internal networking instead of NSURLConnection . I have hit an interesting problem and wonder about the internal implementation of the challenge handler of NSURLSession / NSURLSessionTask . - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition

NSURLSessionUploadTask get response data

老子叫甜甜 提交于 2019-12-06 06:06:11
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: self, delegateQueue: nil) I've implemented 2 methods: func URLSession(session: NSURLSession, dataTask:

NSURLSession, upload task - Get actual bytes transferred

心不动则不痛 提交于 2019-12-06 03:46:03
问题 I was getting bug reports that my iOS app failed upload of images on slow connections. While my timeout probably wasn't high enough, there was another issue. I found that upload progress quickly went to 100% even though I could see in Charles that bytes were still being transferred. I use the following method of NSURLSession: - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromData:(NSData *)bodyData completionHandler:(void (^)(NSData *data, NSURLResponse *response,

NSURLSession - download and do *not* decompress gzip?

扶醉桌前 提交于 2019-12-06 03:35:46
问题 I'm using NSURLSession 's dataTaskWithRequest to download a file. It's gzipped, and it is automatically decompressed. However, I don't want it to be - I want the gzipped source. Is there any way to disable decompression? 回答1: NSURLSession automatically inserts this value to your request's header: "Accept-Encoding: gzip;q=1.0, compress;q=0.5" which causes the downloaded data to be automatically decoded. So I think you should start by replacing the value of "Accept-Encoding" with something else

Unit tests with NSURLSession

旧时模样 提交于 2019-12-06 02:47:32
问题 I'd like to write unit tests for methods that use the shared NSURLSession , and in particular, NSURLSessionDataTask to download data. Basically, I would like the target methods to receive mock responses/data without requiring an internet connection. What is the less unobtrusive way of mocking these components? I was thinking of populating NSURLCache with mock responses and data but I feel this assumes too much of how NSURLSession and NSURLSessionDataTask work. Any other suggestions? 回答1: I've

Image(or video) posting to server in Swift

ぃ、小莉子 提交于 2019-12-05 18:44:57
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/json", forHTTPHeaderField: "Content-Type") request.addValue("application/json", forHTTPHeaderField: