MPMoviePlayerViewController使用setDefaultCredential从yahoo托管站点保护URL

okg*_*kgo 6 iphone objective-c ipad

我正在使用MPMoviePlayerViewController文档中提到的类似代码.但它不起作用.它说"你没有被授权......".我的服务器托管在雅虎上.网址是这样的.

代码如下

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];
Run Code Online (Sandbox Code Playgroud)

小智 1

如果这与 UIWebView 访问相同,您将首先打开 NSURLConnection 并在相关委托方法中传递凭据,然后一旦收到响应,您将取消连接,然后使用该连接启动 MPMoviePlayerViewController。