Question: i have to make some updates to a web site built using expression engine. There is no staging area available so i'd like to create a test area of the web site accessible only to site owners allowing them to preview the changes. 

Ordinarily, i'd just create a "test" folder and direct the users to this URL. I'm new to Expression Engine and not sure how to achieve this. Any help would be much appreciated.

Answer: 
The secret to HTTP basic authentication using cocoa is knowing NSURL and the related classes.

* NSURL
* NSURLRequest/NSMutableURLRequest
* NSURLConnection
* NSURLCredential
* NSURLCredentialStorage
* NSURLProtectionSpace
* UIWebView/WebView/NIWebController etc.

The real magic comes from NSURLConnection. In the words of the devDocs, "An NSURLConnection object provides support to perform the loading of a URL request." If you want to load some a URL in the background without displaying it you would use NSURLConnection. The real power of the NSURLConnection is in the method

```
+ (NSURLConnection *)connectionWithRequest:(NSURLRequest *)request delegate:(id < NSURLConnectionDelegate >)delegate

```

The NSURLConnectionDelegate protocol has methods for responding to successful connections, fatal errors, and authentication challenges. If you are trying to access data Protected by HTTP basic authentication this is how Cocoa does it. At this point an example should bring some clarity.

```
//basic HTTP authentication
NSURL *url = [NSURL URLWithString: urlString];
NSMutableURLRequest *request;
request = [NSMutableURLRequest requestWithURL:url
                              cachePolicy:NSURLRequestReloadIgnoringCacheData
                          timeoutInterval:12];
[self.webView openRequest:request];
(void)[NSURLConnection connectionWithRequest:request delegate:self];

```

This creates a URL. From the URL a URLRequest is created. The URLRequest is then loaded in the web view. The Request is also used to make a URLConnection. We don't really use the connection, but we need to receive notifications about authentication so we set the delegate. There are only two methods we need from the delegate.

```
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
{  
    NSURLCredential * cred = [NSURLCredential credentialWithUser:@"username"
                                                    password:@"password"
                                                 persistence:NSURLCredentialPersistenceForSession];
[[NSURLCredentialStorage sharedCredentialStorage]setCredential:cred forProtectionSpace:[challenge protectionSpace]];

}

- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection;
{
    return YES;
}

```

Whenever there is an authentication challenge a credential is added to the credential storage. You also tell the connection to use the credential storage.
Make sure to remember that logging out is not so easy with sessions and UIWebView credentials. See answer here: <https://stackoverflow.com/a/18143902/2116338>.