2011-03-22 68 views
6

我正在使用與MPMoviePlayerViewController文檔中提到的類似的代碼。但它不起作用。它說「你沒有被授權..」。我的服務器託管在雅虎上。網址是一樣的東西this.MPMoviePlayerViewController使用setDefaultCredential從雅虎託管網站保護的URL

代碼如下

NSURLCredential *credential = [[NSURLCredential alloc] 
          initWithUser:@"abc" 
          password:@"xyz" 
          persistence: NSURLCredentialPersistencePermanent]; 

NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] 
            initWithHost:@"www.someurl.com" 
            port:80 
            protocol:@"http" 
            realm:@"tmp" 

    authenticationMethod:NSURLAuthenticationMethodDefault]; 

[[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential 
               forProtectionSpace:protectionSpace]; 

[protectionSpace release]; 
[credential release]; 
    MPMoviePlayerViewController *movie = [[[MPMoviePlayerViewController alloc] initWithContentURL:url] autorelease]; 

回答

1

如果這是一樣的UIWebView的訪問,你會先打開一個NSURLConnection的,並通過在相關的委託方法的憑據,然後,一旦你得到迴應您取消連接,然後用連接啓動MPMoviePlayerViewController。