Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS website interaction (NSURLConnection) design/pattern
    text
    copied!<p>This is a question about how to design an app that interacts with a website.</p> <p>I have an app which queries a website for information, done with an asynchronous <code>NSURLConnection</code> (which I think is the preferred methode in iOS). The website in question does not have an api/web-service interface. Interaction is done like a browser would do, send request, receive answer, interpret the answer to determine next action. </p> <p>The site is also secured with a username and password and does. So when I want to interact with the website (let's say, usecases like: "get a list of photo's", "download photo", "upload photo") I need to login first and when I'm finished I'm logging out.</p> <p>I'd like to write my functions like this (but I'm very open to suggestions, perhaps I'm looking at it the wrong way)</p> <pre><code>login if login successful get list of photos logout </code></pre> <p>Then after when the user asks for it I'd like to</p> <pre><code>login if login successful download photo logout </code></pre> <p>The problem I'm running into is, every time you fire of an <code>NSURLConnection</code>, the reply is received in <code>-connectionDidFinishLoading</code>. So I need to keep some kind of state to know what to do next, was this login for getting the list of photos or was it a login to download a photo.</p> <p>Now, the problem is not that I cant get this to work, the problem is how to set something like this up cleanly and efficiently so that it can scale so that it can support 20+ or even 50+ usecases and still be easily maintainable. Stressing that not all usecases are as simple as the ones illustrated above.</p> <p>An example of what I'm trying to achieve is for instance the facebook app. That app also needs to login to facebook an support a whole range of usecases like posting an item, downloading posts, like a post, upload photos and numerous others. How have they designed something like this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload