nsurlsession

NSURLSession, upload task - Get actual bytes transferred

三世轮回 提交于 2019-12-04 07:30:56
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, NSError *error))completionHandler and implement the following delegate method to receive progress

Is there a way to use NSURLProtocol in a NSURLSession with custom config?

两盒软妹~` 提交于 2019-12-04 05:23:48
I have a NSURLSession that runs in a background queue. I'm adding my NSURLProtocol subclass to the NSURLsessionConfiguration.protocolClases but the override class func canInitWithRequest(request: NSURLRequest) -> Bool never gets called. This is how I'm adding my NSURLProtocol let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.protocolClasses!.append(MockNetwork) urlSession = NSURLSession(configuration: configuration, delegate: self, delegateQueue: operationQueue) Also I tried with the session not running on background doing but also didn't work: let

Why does connecting back to an iOS background NSURLSession take too long waiting on a lock, crashing the app?

对着背影说爱祢 提交于 2019-12-04 05:22:45
Why would connecting with an NSURLSession through its configuration take so long that it would crash the app on start up: 'failed to launch in time'? I've seen similar crash dumps in many iOS apps including NY Times iOS app and Evernote app. [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:queue] Here's the stack trace: Thread 0: 0 libsystem_kernel.dylib 0x3afb7aa0 semaphore_wait_trap + 8 1 libdispatch.dylib 0x3af04d3d _dispatch_semaphore_wait_slow + 173 2 CFNetwork 0x2febd8e3 -[__NSCFBackgroundSessionBridge setupBackgroundSession] + 379 3 CFNetwork 0x2fef18a1 +

UI get blocked when using NSURLSession

我与影子孤独终老i 提交于 2019-12-04 03:41:33
问题 I'm working on a project which requires a login form, using a webservice for authentication. I have no issue connecting to the server but it seems that NSURLSession blocks my user interface and I really dont know why after a lot of debugging. For simplicity, here's my code in short: NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"example.com/service"]]; //1 //_sessionLogin = [NSURLSession sessionWithConfiguration:sessionConfigurationLogin

How to know if NSURLSessionDataTask response came from cache?

Deadly 提交于 2019-12-04 03:16:28
I would like to determine if the response from NSURLSessionDataTask came from cache, or was served from server I'am creating my NSURLSessionDataTask from request.cachePolicy = NSURLRequestUseProtocolCachePolicy; Two easy options come to mind: Call [[NSURLCache sharedURLCache] cachedResponseForRequest:request] before you make the request, store the cached response, then do that again after you finish receiving data, and compare the two cached responses to see if they are the same. Make an initial request with the NSURLRequestReturnCacheDataDontLoad cache policy, and if that fails, make a second

Swift 3: URLSession / URLRequest Not Working

瘦欲@ 提交于 2019-12-04 03:04:15
问题 I am still trying to convert our application from Swift 2 over to Swift 3 because I am being forced to since all of our Apple devices are now running iOS 10. I have gone through the code conversion and thought I was doing well however, while attempting to debug my JSON issues (posted in another question), I am now dealing with requests not even being sent. let params: [String:AnyObject] = [ "email":"\(self.preferences.string(forKey: "preference_email")!)" as AnyObject ] let requestParams:

Background Upload With Stream Request Using NSUrlSession in iOS8

删除回忆录丶 提交于 2019-12-04 02:20:18
问题 Previously in iOS7 when we try to upload with stream request in background we get following exception Terminating app due to uncaught exception 'NSGenericException', reason: 'Upload tasks in background sessions must be from a file' But in iOS8 there is no exception when we try to upload with stream in background. Now my question is 1) Is backgourd upload with uploadTaskWithStreamedRequest: allowed in iOS8? 2) In iOS8 i am using background NSURLConfiguration with uploadTaskWithStreamedRequest

How to do multipart/form-data post request with Swift?

江枫思渺然 提交于 2019-12-04 01:59:52
问题 let Url = String(format: "http://url/ios.php") guard let serviceUrl = URL(string: Url) else { return } let parameterDictionary :[String:String] = ["Episodes" : "http://url/anime/07-ghost.html"] var request = URLRequest(url: serviceUrl) request.httpMethod = "POST" request.setValue("multipart/form-data", forHTTPHeaderField: "Content-Type") request.httpBody = NSKeyedArchiver.archivedData(withRootObject: parameterDictionary) let session = URLSession.shared session.dataTask(with: request) { (data,

ETag and If-None-Match HTTP Headers are not working

一个人想着一个人 提交于 2019-12-04 01:58:07
I have a file in my webserver and I am downloading that to my app everytime I access it because its possible that file content might be changed But If it is changed I would like to download that time only so bandwidth can be saved and fortunately that's what this ETag and If-None-Match header fields are for. When I make a request first time ,I retrieve the ETag from the HTTP response headers In the subsequent requests to download that file I'd attach the Etag value for If-None-Match headerfield so that if there is no change then I'd get HTTP response status code 304 or else I'd get 200 if

Simple example of NSURLSession with authentication

痴心易碎 提交于 2019-12-04 01:49:14
问题 I have written a REST service that serves up some data. It is passcode protected. I am trying to write a background process that will grab the data and stuff it into a sqlLite db I have in the app. I did this initially without authentication using : - (void) callWebService { dispatch_sync(kBgQueue, ^{ NSData* data = [NSData dataWithContentsOfURL: scoularDirectoryURL]; [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES]; }); } This worked fine but I don