To play a network stream whose URL requires access credentials, first create an appropriate NSURLCredential object. Do this by calling, for example, the initWithUser: password: persistence: method, as shown here:
NSURLCredential *credential = [[NSURLCredential alloc]
initWithUser: @"userName"
password: @"password"
persistence: NSURLCredentialPersistenceForSession];
self.credential = credential;
[credential release];
In addition, create an appropriate NSURLProtectionSpace object, as shown here. Make appropriate modifications for the realm you are accessing:
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost: "@streams.mydomain.com"
port: 80
protocol: @"http"
realm: @"mydomain.com"
authenticationMethod: NSURLAuthenticationMethodDefault];
self.protectionSpace = protectionSpace;
[protectionSpace release];
Add the URL credential and the protection space to the Singleton
NSURLCredentialStorage object. Do this by calling, for example, the setCredential:forProtectionSpace: method, as shown here:
[[NSURLCredentialStorage sharedCredentialStorage]
setDefaultCredential: credential
forProtectionSpace: protectionSpace];
With the credential and protection space information in place, you can then play the protected stream.