nsurlsession

Convert NSURLConnection to NSURLSessionUploadTask example

孤人 提交于 2019-12-31 03:07:25
问题 Hi everyone and thanks in advance for any help providing in understanding in how to convert some NSURLConnection code into the newer NSURLSession. What I am trying to do is to make a POST request to a server, and send a photo base 64 encoded for the key "photo". Below I have an working example written in NSURLConnection and I will like to convert it into NSURLSession. As I read on the apple documentation from what I understood I should use a Data tasks because in my case it is an image and if

NSURLErrorDomain Code=-1001 error when a http post request is sent

你离开我真会死。 提交于 2019-12-30 17:16:30
问题 I am using the following code to post an image to my server. @IBAction func postButtonPressed(sender: UIButton) { let task = NSURLSession.sharedSession().dataTaskWithRequest(createRequest("http://xx.xx.xxx.xxx/xxxx/"), completionHandler: { data, response, error in println(NSString(data: data, encoding: NSUTF8StringEncoding)) }) task.resume() } where createRequest() creates the required NSURLRequest object. This works fine when I use a simulator . The problem is that I am getting the following

URLSessionUploadTask getting automatically cancelled instantly

这一生的挚爱 提交于 2019-12-30 06:29:49
问题 I'm having this weird issue in which a newly created URLSessionUploadTask gets cancelled instantly. I'm not sure if it's a bug with the current beta of Xcode 8. I suspect it might be a bug because the code I'm about to post ran fine exactly once. No changes were made to it afterwards and then it simply stopped working. Yes, it literally ran once, and then it stopped working. I will post the error near the end. I will post the code below, but first I will summarize how the logic here works. My

Swift 3, URLSession dataTask completionHandler not called

烈酒焚心 提交于 2019-12-30 03:30:27
问题 I am writing a library, So not using UIKit, Even in my iOS app same code works, but when i execute in command line in doesn't . In PlayGround also it seems working. For some reason callback is not getting triggered, so print statements are not executing. internal class func post(request: URLRequest, responseCallback: @escaping (Bool, AnyObject?) -> ()) { execTask(request: request, taskCallback: { (status, resp) -> Void in responseCallback(status, resp) }) } internal class func

setting limit on concurrent tasks in AFNetworking 2 running AFHTTPSessionManager

一个人想着一个人 提交于 2019-12-29 03:18:25
问题 so I know that in the old AFNetworking this was possible using the AFHTTPClient, and I know that if I use AFHTTPRequestOperationManager I can set the queue's limit, but I can't make AFHTTPSessionManager to run only x requests at a time without implementing it by myself using the success block (which I don't want to). The following code did NOT limit my connections: AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.operationQueue.maxConcurrentOperationCount = 1; In line

How to use NSURLSession to determine if resource has changed?

只愿长相守 提交于 2019-12-28 13:58:13
问题 I'm using NSURLSession to request a JSON resource from an HTTP server. The server uses Cache-Control to limit the time the resource is cached on clients. This works great, but I'd also like to cache a deserialized JSON object in memory as it is accessed quite often, while continuing to leverage the HTTP caching mechanisms built into NSURLSession. I'm thinking I can save a few HTTP response headers: Content-MD5 , Etag , and Last-Modified along with the deserialized JSON object (I'm using those

asynchronous upload with NSURLSession will not work but synchronous NSURLConnection does

荒凉一梦 提交于 2019-12-28 05:42:27
问题 edit: I need to upload a file asynchronously from an iPhone to a Python server-side process. I'd like to do the request asynchronously so that I can display a busy animation while it's working. The request needs to include the username, password and file as 'multipart/form-data'. I can get it working synchronously using NSURLConnection with the code looking like this:: -(void) uploadDatabase{ Database *databasePath = [[Database alloc] init]; NSString *targetPath = [databasePath

How to programmatically add a proxy to an NSURLSession

大憨熊 提交于 2019-12-28 02:39:13
问题 Looking over the documentation of NSURLSession and NSURLSessionConfiguration , I was under the impression I should configure it with a dictionary like the following: // Create a dictionary to describe the proxy NSDictionary *proxyDict = @{ (NSString *)kCFProxyHostNameKey : @"myProxyHost.com", (NSString *)kCFProxyPortNumberKey : @"12345", (NSString *)kCFProxyTypeKey : (NSString*)kCFProxyTypeHTTP }; // Create a configuration that uses the dictionary NSURLSessionConfiguration *configuration =

How to assign result of NSURLSession to a variable in same method?

拜拜、爱过 提交于 2019-12-25 16:45:12
问题 To say I'm new to Objective-C would be a huge understatement. I'm primarily a Ruby/Rails developer and it completely spoiled me when it comes to OOP & programming in general. After getting tired of reading tutorials, I decided to try to use NSRULSession to hit one of my Rails apps (an Elder Scrolls Online skill planner) & display some of the JSON response on my iOS app. Delegates make no sense, I'm not sure how to break this functionality up into methods, etc, so I thought I'd keep it simple

get file path when downloading with NSURLSession

守給你的承諾、 提交于 2019-12-25 14:16:52
问题 I want to play music while downloading, so i play music with local file, how can i get file path in tmp directory while downloading with NSURLSession. The method URLSession:downloadTask:didFinishDownloadingToURL: than only call while file downloaded, so what should i do 回答1: If you want to get file location as it's being downloaded, just don't use download task. For example, create a NSURLSessionDataTask and stream it to persistent storage yourself (e.g. create your own NSOutputStream for