nsurlsession

iOS: NSURLSession category methods not being found at runtime

北城以北 提交于 2019-11-29 06:01:05
I wanted to create a category on NSURLSession. The app compiles ok, but when I attempt to call the category methods I get -[__NSCFURLSession doSomething]: unrecognized selector sent to instance 0xbf6b0f0 <unknown>:0: error: -[NSURLSession_UPnPTests testCategory] : -[__NSCFURLSession doSomething]: unrecognized selector sent to instance 0xbf6b0f0 Very strange, here is a test class I built to show the issue. The category on the NSString works fine, but the category on NSURLSession fails to find the method at runtime. I suspect this is something internal. Opinions please :-) #import <XCTest/XCTest

How do I get the NSURLResponse before the downloadTaskWithURL finishes?

扶醉桌前 提交于 2019-11-29 05:17:46
This is my code for download : let url = NSURL(string:"http://www.zastavki.com/pictures/originals/2013/Photoshop_Image_of_the_horse_053857_.jpg")! let documentsDirectoryURL = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first as! NSURL NSURLSession.sharedSession().downloadTaskWithURL(url, completionHandler: { (location, response, error) -> Void in if let error = error { println(error.description) } else { println("Finished downloading \"\(response.suggestedFilename)\".") println(location.path!) println("Started saving \"\(response.suggestedFilename)\".") if

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) in iOS 9 with Xcode 7.1

北城以北 提交于 2019-11-29 02:55:57
I am using iOS 9 as target & using Xcode 7.1, tried everything as my level best for all the solutions of ATS but didn't work. Below is the following error description coming at console. If any suggestion comes I will be obliged. Some of the key things here are - NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) Error excluding Main.db from backup Error Domain=NSCocoaErrorDomain Code=4 "The file “Main.db” doesn’t exist." UserInfo={NSURL=file:///Users/Raj/Library/Developer/CoreSimulator/Devices/BC3A0589-3B9A-4AFD-8F2A-B1C92FA341DD/data/Containers/Data/Application

How to find and cancel a task in NSURLSession?

本秂侑毒 提交于 2019-11-29 01:35:06
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? 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 with all outstanding data, upload, and download tasks in a session. Then check task.originalRequest.URL for

Weird NSURLSessionDownloadTask behavior over cellular (not wifi)

假装没事ソ 提交于 2019-11-28 23:02:52
问题 I've enabled Background Modes with remote-notification tasks to download a small file (100kb) in background when the app receives a push notification. I've configured the download Session using NSURLSessionConfiguration *backgroundConfiguration = [NSURLSessionConfiguration backgroundSessionConfiguration:sessionIdentifier]; [backgroundConfiguration setAllowsCellularAccess:YES]; self.backgroundSession = [NSURLSession sessionWithConfiguration:backgroundConfiguration delegate:self delegateQueue:

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

馋奶兔 提交于 2019-11-28 22:11:32
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-to-read gist ) - (void) addTasksToSessionWithTaskObject:(Task*)taskObject

Average progress of all the NSURLSessionTasks in a NSURLSession

非 Y 不嫁゛ 提交于 2019-11-28 19:27:30
An NSURLSession will allow you to add to it a large number of NSURLSessionTask to download in the background. If you want to check the progress of a single NSURLSessionTask , it’s as easy as double taskProgress = (double)task.countOfBytesReceived / (double)task.countOfBytesExpectedToReceive; But what is the best way to check the average progress of all the NSURLSessionTasks in a NSURLSession ? I thought I’d try averaging the progress of all tasks: [[self backgroundSession] getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *allDownloadTasks) { double

How can I check that an NSData blob is valid as resumeData for an NSURLSessionDownloadTask?

99封情书 提交于 2019-11-28 19:21:28
问题 I have an app that's using background downloads with the new NSURLSession APIs. When a download cancels or fails in such a way that NSURLSessionDownloadTaskResumeData is provided, I store the data blob so that it can be resumed later. A very small amount of the time I am noticing a crash in the wild: Fatal Exception: NSInvalidArgumentException Invalid resume data for background download. Background downloads must use http or https and must download to an accessible file. The error occurs here

setting limit on concurrent tasks in AFNetworking 2 running AFHTTPSessionManager

余生颓废 提交于 2019-11-28 17:58:57
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 with an interesting discussion here , I have a lot of requests to my server and I choke it until I get

How do I unit test HTTP request and response using NSURLSession in iOS 7.1?

£可爱£侵袭症+ 提交于 2019-11-28 17:54:39
I'd like to know how to "unit test" HTTP requests and responses using NSURLSession. Right now, my completion block code does not get called when running as a unit test. However, when the same code is executed from within the AppDelegate (didFinishWithLaunchingOptions), the code inside the completion block is called. As suggested in this thread, NSURLSessionDataTask dataTaskWithURL completion handler not getting called , the use of semaphores and/or dispatch_group is needed "to make sure the main thread is blocked until the network request finishes." My HTTP post code looks like the following.