nsurlsession

NSURLSession background download - resume over network failure

可紊 提交于 2019-11-28 17:35:56
After reading the Apple documentation about the background download with the new iOS7 api (NSURLSession), I'm a bit disappointed. I was sure that Apple was managing the pause/resume over the network availability in the background (or provide an option to do so) but no… So reading the documentation, this is what we've got: https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/URLLoadingSystem/NSURLSessionConcepts/NSURLSessionConcepts.html When any task completes, the NSURLSession object calls the delegate’s URLSession:task:didCompleteWithError: method with either an error

Best practices for making a queue of NSURLSessionTasks

和自甴很熟 提交于 2019-11-28 17:34:37
What are the best practices for making a serial queue of NSURLSessionTasks ? In my case, I need to: Fetch a URL inside a JSON file ( NSURLSessionDataTask ) Download the file at that URL ( NSURLSessionDownloadTask ) Here’s what I have so far: session = [NSURLSession sharedSession]; //Download the JSON: NSURLRequest *dataRequest = [NSURLRequest requestWithURL:url]; NSURLSessionDataTask *task = [session dataTaskWithRequest:dataRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { //Figure out the URL of the file I want to download: NSJSONSerialization *json =

iOS - Best practice to save Images locally - NSCache vs Save in Document Directory

老子叫甜甜 提交于 2019-11-28 16:52:38
问题 I'm developing an app that similar to Instagram feed (tableviews with cells that contain images and some labels). For all the data I'm getting from the database, I'm using Data Task (because it doesn't take much to receive them), but for the images (which their url's I get with the Data request), I need to save locally for future use (improve user experience). My logic is the following: Save in NSCache or in Document Directory, the images inside folder with the date they been downloaded

NSURLSession and amazon S3 uploads

为君一笑 提交于 2019-11-28 16:35:23
I have an app which is currently uploading images to amazon S3. I have been trying to switch it from using NSURLConnection to NSURLSession so that the uploads can continue while the app is in the background! I seem to be hitting a bit of an issue. The NSURLRequest is created and passed to the NSURLSession but amazon sends back a 403 - forbidden response, if I pass the same request to a NSURLConnection it uploads the file perfectly. Here is the code that creates the response: NSString *requestURLString = [NSString stringWithFormat:@"http://%@.%@/%@/%@", BUCKET_NAME, AWS_HOST, DIRECTORY_NAME,

NSURLSession Authentication

自闭症网瘾萝莉.ら 提交于 2019-11-28 13:24:22
问题 I tried to use the swift code found here on the website found here, but the response is html code with the two errors: "You must enter a password!" and "You must enter a User name!" I am new to NSURLSession and tried to change the string for authentication but nothing worked to change the response. Here is my code: let config = NSURLSessionConfiguration.defaultSessionConfiguration() let userPasswordString = "username@gmail.com:password" let userPasswordData = userPasswordString

NSURLSession: uploading assets with background transfer

与世无争的帅哥 提交于 2019-11-28 11:32:34
What's the best approach to use background transfer to upload assets from gallery? Seems like uploadTaskWithRequest:fromData: doesn't work with NSURLSession created with backgroundSessionConfiguration since it causes an exception: "Terminating app due to uncaught exception 'NSGenericException', reason: 'Upload tasks in background sessions must be from a file". Judging from the exception description background transfer shouldn't work with streamed upload tasks too. Fair enough. uploadTaskWithRequest:fromFile: is the first thing that comes to mind when you think about uploading data that you

iOS9 - HTTP Connection Error

帅比萌擦擦* 提交于 2019-11-28 10:58:44
I got 3 error when i update my Xcode 1- App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 2- CFNetwork SSLHandshake failed (-9824) 3- NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824) I tried: <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>yourdomain.com</key> <dict> <!--Include to allow subdomains--> <key>NSIncludesSubdomains</key> <true/> <!--Include to allow HTTP requests--> <key

Why is a HTTPS NSURLSession connection only challenged once per domain?

本秂侑毒 提交于 2019-11-28 10:29:43
When connecting via HTTPS to a server, I implement the NSURLSessionDelegate method URLSession:didReceiveChallenge:completionHandler: to implement some custom functionality. The problem is that this delegate method is only being called the first time a request is made (subsequent requests do not invoke this method). My custom functionality requires the delegate method to be called for every request. Here's an example: - (IBAction)reload:(id)sender { NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration] delegate:self

How to use NSURLSession to determine if resource has changed?

依然范特西╮ 提交于 2019-11-28 09:34: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 3 fields since I've noticed not all HTTP servers return Content-MD5 , otherwise that'd be sufficient

Manage the number of active tasks in a background NSURLSession

只愿长相守 提交于 2019-11-28 09:26:06
问题 It seems that when you enqueue too many tasks (say, hundreds) on a background NSURLSession , it doesn't work well. How can you keep the number of enqueued tasks at a small fixed number, say 10? 回答1: In the class that is responsible for enqueueing tasks, have a ivar to track the active tasks, e.g. // In MySessionWrapper.m @interface MySessionWrapper () { NSMutableSet *activeTaskIds; } @end When you enqueue a task, you add its ID to that set: [activeTaskIds addObject:@([task taskIdentifier])]