nsurlconnection

iOS - communication between API object and controllers

落花浮王杯 提交于 2019-12-04 15:38:40
I am curious about 2 things: 1 whats the efficient and easy-to-scale way to design communication between object that communicates with API and viewcontrollers 2 how to design the communicating object itself (how to design methods to be scalable,..) (My approach mention below is messy, I know, but the deadlines were crazy and until now I didn't have time to think about it really.) Let me introduce the task I was dealing with: I had to write 2-3 apps depending on communication with API. There was about 10-15 different methods that the API responded to (send via http POST, result in JSON). Of

Clear NSURLConnection cache

戏子无情 提交于 2019-12-04 15:18:48
问题 Is there a way to clear NSURLConnection cache? I used that to download some strings but I keep getting the same strings even though I changed that from my server. 回答1: You can clear the cache explicitly using: obj-c [[NSURLCache sharedURLCache] removeAllCachedResponses]; swift URLCache.shared.removeAllCachedResponses() 回答2: You specify cache policy when you create your NSURLRequest object. Set the cachePolicy property to NSURLRequestReloadIgnoringCacheData or use the initWithURL:cachePolicy

NSURLConnection Progress Bar with sendAsynchronousRequest Objective-C

穿精又带淫゛_ 提交于 2019-12-04 15:13:18
I am downloading a bunch of largish zip files with the following method. It can take a little while and so I'd like to display a progress bar. I've researched how to do with with the delegate methods for NSURLConnection and it seems straightforward, however I want to achieve the same thing with "sendAsynchronousRequest". How can I get the number of bytes downloaded as it downloads as well as the total number of bytes expected so that I can display a progress bar? I understand that I cannot use the delegate methods if I kick off a download in the manner I am doing it. // Begin the download

connectionDidFinishLoading - how to force update UIView?

一个人想着一个人 提交于 2019-12-04 14:32:05
问题 I am able to download a ZIP file from the internet. Post processing is done in connectionDidFinishLoading and works OK except no UIView elements are updated. For example, I set statusUpdate.text = @"Uncompressing file" but that change does not appear until after connectionDidFinishLoading has completed. Similarly, the UIProgressView and UIActivityIndicatorView objects are not updated until this method ends. Is there any way to force an update of the UIView from within this method? I tried

didReceiveAuthenticationChallenge getting called only once iPhone

坚强是说给别人听的谎言 提交于 2019-12-04 13:03:15
I am connecting to server using NSURLConnection . The server asks for basic authentication for which I am using the delegate methods :- didReceiveAuthenticationChallenge . But this gets called only once. If I change password to some different value, then this delegate methods does not get called and it takes my login as successful? Any kind of help will be appreciated. Thanks. Solved! It turns out that NSURLConnection was actually behaving correctly - that is, didReceiveAuthenticationChallenge: was being called for every authentication challenge. The problem was that the server was not sending

Using a single shared background thread for iOS data processing?

本小妞迷上赌 提交于 2019-12-04 12:57:35
问题 I have an app where I'm downloading a number of resources from the network, and doing some processing on each one. I don't want this work happening on the main thread, but it's pretty lightweight and low-priority, so all of it can really happen on the same shared work thread. That seems like it'd be a good thing to do, because of the work required to set up & tear down all of these work threads (none of which will live very long, etc.). Surprisingly, though, there doesn't seem to be a simple

How to make webservice pass errors through NSURLConnection's connection:didFailWithError:?

馋奶兔 提交于 2019-12-04 11:16:10
What does a web service need to do to cause NSURLConnection's delegate to receive the connection:didFailWithError: message? For example: iOS app passes a token to the web service, web service looks up the token, and then the web service needs to respond with an error saying "invalid token" or something of the like. Currently, the data is received, and in " connectionDidFinishLoading :" is parsed for error messages. This means I'm error checking in two places, which I am trying to avoid. I have both the iOS app and web service completely under my control. In my experience (the three most

What is the situation regarding the NSURLConnection timeout with iOS5?

烂漫一生 提交于 2019-12-04 11:05:36
I'm trying to find a definitive answer to if it possible to set the timeout value for using NSURLConnection in iOS 5 (I would like to set it to 30 seconds). I've searched past postings on this but the information seems contradictory. For example, this posting NSURLConnection timeout? says Apple mandates a 4 minute minimum timeout - though I cannot find any Apple documentation to support this. THis posting says the 240 limit comes from an apple forum thread NSMutableURLRequest not obeying my timeoutInterval They say this limit is only for POSTs when the body isn't empty. Does that imply its

NSURLConnection getting JSON File

不想你离开。 提交于 2019-12-04 10:44:34
My iOS app is getting the code inside (ex. 101), and by that code it reads JSON file (ex. 101.json) on server and read the data inside. Everything is working good, but how to do that if there's no file (for that code) on server (now it's just showing no data if file not found) and if there's no internet connection just to get data from JSON file inside the app? Here's my code: NSString *baseURLStr = @"http://myserverurl/"; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[baseURLStr stringByAppendingFormat:@"%d/%d.json", int1, int2]]]; NSData *data = [NSURLConnection

Recommended alternative to webkit for server-sent events on iOS [closed]

这一生的挚爱 提交于 2019-12-04 10:30:02
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I would like to receive Server-Sent Events in my native iOS app however am not using webkit/Safari. From what I've found, NSURLConnection is poor fit as it chunks response . I've also looked at ZTWebSocket library (obviously nice, but I'm seeking SSE, not web sockets). Would CocoaAsyncSocket be appropriate? Or limited to pure TCP Socket communication? I have a sneaking suspicion that I am missing