nsurlsession

asynchronous upload with NSURLSession will not work but synchronous NSURLConnection does

十年热恋 提交于 2019-11-27 20:18:24
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 getPathToDatabaseInDirectory]; NSData *dbData = [NSData dataWithContentsOfFile:targetPath]; NSString *url = @"http:/

NSURLConnection deprecated in iOS9

烈酒焚心 提交于 2019-11-27 19:47:59
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]; documentsURL = [documentsURL URLByAppendingPathComponent:@"localFile.pdf"]; [data writeToURL

iOS 9.3 : An SSL error has occurred and a secure connection to the server cannot be made

泪湿孤枕 提交于 2019-11-27 19:47:18
I am getting following error with self signed certificate Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made. while testing web-services for one of my demo app with iOS 9.3 XCode 7.3 Swift 2.2 Alamofire 3.3.0 and Local server : https://filename.hostname.net Note: before assuming its Duplicate, I would request please read it all the way,even same i have reported to apple dev forums Using Alamofire Library func testAlamofireGETRequest() -> Void { Alamofire.request(.GET, "https://filename.hostname.net/HelloWeb/service/greeting

How to get data to return from NSURLSessionDataTask

我们两清 提交于 2019-11-27 16:55:34
问题 I have a registration view controller which handles all the user input and calls a function in another class (wsClass) passing to it, that data as an NSDictionary. The function in wsClass is called and the connection is made and data is returned from the server and available within the session. My question is how do I return that data to the registration viewcontroller where the function was originally called, it's always coming up empty. Here is the call in registrationViewController:

How to find and cancel a task in NSURLSession?

拈花ヽ惹草 提交于 2019-11-27 15:59:32
问题 I'm using an NSURLSession object to load images in my application. That could be loading several images simultaneously. In some moments I need to cancel the loading of one specific image and continue loading others. Could you suggest the correct way to do that? 回答1: To get tasks list you can use NSURLSession's method - (void)getTasksWithCompletionHandler:(void (^)(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks))completionHandler; Asynchronously calls a completion callback

URLresponse is not retrieved after storing in cache using storeCachedResponse

て烟熏妆下的殇ゞ 提交于 2019-11-27 15:42:14
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, diskCapacity: 500 * 1024 * 1024, diskPath: "something") let configuration = URLSessionConfiguration.default

Prevent NSURLSession from caching responses

冷暖自知 提交于 2019-11-27 14:45:34
问题 Why does it cache responses. It returns previously fetched responses. It even works if turning off the network connection. Resetting the iOS simulator did not seem to work either. Making a request, then again with internet offline does work (cached). public let urlSession: NSURLSession public init() { // ... var configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.requestCachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData urlSession =

Unable to sustain a Constant Speed while Uploading files in the background with NSURLSession

落爺英雄遲暮 提交于 2019-11-27 14:16:48
问题 I am trying to upload some 100 images to S3 in the background with AFURLSessionManager in small batches of 10 like what is being done here- Manage the number of active tasks in a background NSURLSession I am using a shared NSURLSession and adding tasks according more tasks to this when some tasks are completed. Average size of each file is about 1.6 MB and the number of tasks that are guaranteed to run per a task queue is 5 Here is my method for adding the tasks: (also available as an easier

AFNetworking 3.0 AFHTTPSessionManager using NSOperation

北城余情 提交于 2019-11-27 12:27:38
问题 I'm stuck now some time and I need help. So in AFNetworking 2.0 we have AFHTTPRequestOperation so I could easily use NSOperationQueue and have some dependencies. So what we have now is only AFHTTPSessionManager and NSURLSession that does not subclass NSOperation . I have class APIClient that subclasses AFHTTPSessionManager . I am using that class as singleton as sharedClient . I have overriden GET and POST so for example GET looks this: - (NSURLSessionDataTask *)GET:(NSString *)URLString

Showing the file download progress with NSURLSessionDataTask

只愿长相守 提交于 2019-11-27 12:24:16
I want to display file download progress (how many bytes are received) of particular file. It works fine with the NSURLSessionDownloadTask .My question is I want to achieve the same with the NSURLSessionDataTask. Here is the code which receives file into NSData and writes to document folder: NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]]; NSURLSessionDataTask * dataTask = [defaultSession