It sounds like you're thinking of homebrewing your own code to talk to the gateway, instead of using Couchbase Lite? That's quite unusual.
You can use either HTTP Basic auth, or cookies. If you want to use HTTP auth, implement the authentication method in your NSURLConnection delegate class, and provide the credentials when it's called. If you want to use cookie auth, first POST the credentials to /dbname/_session (
documentation here) and the response will include a Set-Cookie header; from then on NSURLConnection will take care of sending back the session cookie.