Ios 使用MPMOVIEWPLAYERCONTROLER播放受Windows身份验证保护的mp4视频(url)

Ios 使用MPMOVIEWPLAYERCONTROLER播放受Windows身份验证保护的mp4视频(url),ios,xcode,authentication,Ios,Xcode,Authentication,我有一个受Windows身份验证保护的.mp4视频(url)。我想用MPMoviePlayerController玩 - (BOOL)connection:(NSURLConnection*)conn canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace { if([[protectionSpace authenticationMethod] isEqualToString:NSUR

我有一个受Windows身份验证保护的.mp4视频(url)。我想用MPMoviePlayerController玩

- (BOOL)connection:(NSURLConnection*)conn  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])  
        return YES;  

    // Explicitly reject ServerTrust. This is occasionally sent by IIS.  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])  
        return NO;  

    return NO;  
}  
我已经实现了一些代码,我相信我快成功了

- (BOOL)connection:(NSURLConnection*)conn  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])  
        return YES;  

    // Explicitly reject ServerTrust. This is occasionally sent by IIS.  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])  
        return NO;  

    return NO;  
}  
因此,我尝试使用NSURLConnection“解锁”MP4URL。它可以工作,但是当我尝试使用initWithContentURL访问同一个url时,它不起作用。(它无法“看到”我以前输入的信息

- (BOOL)connection:(NSURLConnection*)conn  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])  
        return YES;  

    // Explicitly reject ServerTrust. This is occasionally sent by IIS.  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])  
        return NO;  

    return NO;  
}  
因此,问题是:如何永久锁定文件夹/url,或者如何为MPMoviePlayerController提供NSURL连接而不是NSURL

- (BOOL)connection:(NSURLConnection*)conn  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])  
        return YES;  

    // Explicitly reject ServerTrust. This is occasionally sent by IIS.  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])  
        return NO;  

    return NO;  
}  
1-因此,以下是我采取的步骤:

- (void)viewDidLoad{
    [super viewDidLoad];
    //[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL       URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]]];
    [self tryConnection];
}
- (BOOL)connection:(NSURLConnection*)conn  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])  
        return YES;  

    // Explicitly reject ServerTrust. This is occasionally sent by IIS.  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])  
        return NO;  

    return NO;  
}  
2-->我正在尝试访问受保护的URL(此操作正常)

- (BOOL)connection:(NSURLConnection*)conn  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])  
        return YES;  

    // Explicitly reject ServerTrust. This is occasionally sent by IIS.  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])  
        return NO;  

    return NO;  
}  
3-这是正确的称呼

- (BOOL)connection:(NSURLConnection*)conn  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])  
        return YES;  

    // Explicitly reject ServerTrust. This is occasionally sent by IIS.  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])  
        return NO;  

    return NO;  
}  
4-这是正确的称呼

- (BOOL)connection:(NSURLConnection*)conn  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])  
        return YES;  

    // Explicitly reject ServerTrust. This is occasionally sent by IIS.  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])  
        return NO;  

    return NO;  
}  
- (void)connection:(NSURLConnection*)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge{
    NSLog(@"didReceiveAuthenticationChallenge");
        if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodNTLM])
            [[challenge sender] useCredential:[NSURLCredential  
                                          credentialWithUser:@"1234"  
                                          password:@"5678"  
                                          persistence:NSURLCredentialPersistenceNone] forAuthenticationChallenge:challenge]; 

}
4-这是正确调用的。从这里开始,这很好,因为我知道url是解锁的。那么…如何使用MPMoviePlayer播放它

- (BOOL)connection:(NSURLConnection*)conn  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])  
        return YES;  

    // Explicitly reject ServerTrust. This is occasionally sent by IIS.  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])  
        return NO;  

    return NO;  
}  
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;{
    NSLog(@"received response via nsurlconnection");
    [self moviePlayerGO];
}
4-保持黑色…:(

- (BOOL)connection:(NSURLConnection*)conn  canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])  
        return YES;  

    // Explicitly reject ServerTrust. This is occasionally sent by IIS.  
    if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])  
        return NO;  

    return NO;  
}  

我也尝试过这个:(运气不好,很抱歉格式化)-(void)连接:(NSURLConnection*)连接didReceiverResponse:(nsurResponse*)响应;{NSURL*movieURL=[NSURL URLWithString:@;moviePlayer=[MPMoviePlayerController alloc]初始化WithContentUrl:connection.currentRequest.URL];moviePlayer=[[MPMoviePlayerController alloc]init];moviePlayer.controlStyle=MPMovieControlStyleFullscreen;moviePlayer.shouldAutoplay=YES;…[self.view addSubview:[moviePlayer视图]];}最后一条评论:即使我试图直接从safari访问视频,它也不会出现!从一个没有身份验证的链接,它会出现,从一个请求(并提供)身份验证的链接,我得到一个带有“停止”的视频。