0

I'm currently building an app which will load a web page. Based on some user actions and response, I need to send a HTTP GET request. I realize that I have two options to achieve this:

  • JavaScript - I can use JavaScript to make an AJAX request using my embedded JS file
  • NSURLConnection - native IOS

Now my question is what is better in terms of UI responsiveness. I realize that NSURLConnection may be a blocking call. Are there advantages of using NSURLConnection over AJAX? Thanks in advance.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Will K
  • 13
  • 3
  • Depends what your download is for (what you're downloading). When you say ajax, I imagine you mean while inside a UIWebView? And the alternative NSURLConnection would have to be called natively in iOS? What will you be downloading, and what would you want to do with the downloaded data? – roycable May 08 '14 at 03:33
  • 1
    "I realize that `NSURLConnection` may be a blocking call." If you use either `sendAsynchronousRequest` or the delegate-based implementation, it's going to run asynchronously and won't be "blocking." – Rob May 08 '14 at 03:38
  • Unless you were writing a web-based app, I have a hard time imagining why you'd want to add the JavaScript/AJAX layer on top of this. For a native app, `NSURLConnection` (or a framework built around `NSURLConnection`, such as [AFNetworking](https://github.com/AFNetworking/AFNetworking)), seems like the way to go. Why add that extra layer? – Rob May 08 '14 at 03:47
  • Thanks guys. I'm not downloading but was trying to make a REST call to a backend server. What you guys said make sense. I was more concerned about the responsiveness of my app if I was opening a connection but as pointed out in the comments, it can be done asynchronously. – Will K May 08 '14 at 19:09

0 Answers0