iOS login tutorials or examples

unknown wrote in post #1108500:

Currently i am using devise for authentication on my ruby on rails back
but I do not have any idea of how to link my rails app with an ios app.
Are there any tutorials that show how to create a login in my iOS app?

It depends on what technique you want to use within your iOS app.

There are at least a couple of options:

1. Maintain login state via cookies (like a web browser).

NSURLConnection supports cookies, just like a web browser would. You
login the same way as you would from a web browser. NSURLConnection will
pass any associated cookies it received from the server back with each

It is also a good idea to store the user credentials in the iOS
keychain. The keychain is based on the older C API so can be a bit
tricky to work with, but there exists an Objective-C wrapper for the
keychain in Apple's sample code. I modified their sample code somewhat
to take advantage of modern Objective-C features such as ARC. I could
make that available to you upon request.

2. Use stateless authentication (token based).

You can see examples of taken based authentication as used by sites such
as GitHub. You would have users log into the web site and generate a
user specific API token and enter that token into the iOS app. Once this
is setup then it's just a matter of including the authentication token
somewhere in your NSRequest. A good place to put that would be a custom
request header (e.g. X-Auth-token). Then lookup and authenticate the
user based on their generated token.

The advantage here is that there's no state to maintain within the iOS
app. So if the iOS user were to clear their internet cache it would not
force them to log in again.

Note: While it's trivial to make HTTP requests from an iOS app using
NSURLConnection, it is a lot more complex to make networking robust. For
instance NSURLConnection has a method for sending synchronous request
that is very easy to use. However, you never want to use that on the
main thread. Doing so puts your app at risk of either blocking UI
updates, or in some cases cause the watchdog to kill your app. It is
vital to perform all network operations on a background queue.