2011-03-22 69 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。