【问题标题】:How to handle HTTP Basic Authentication in AVURLAsset?如何处理 AVURLAsset 中的 HTTP 基本身份验证?
【发布时间】:2011-11-09 09:01:25
【问题描述】:
我正在尝试使用 AVPlayer 在 iPhone 中开发自定义电影播放器。但我只是想知道如果 m3u8 url 响应发回身份验证挑战,我该如何处理。我确实知道 didReceiveAuthenticationChallenge 和 NSURLConnection,但不知道它在这种情况下是如何工作的。
感谢任何帮助。
-苏米亚
【问题讨论】:
标签:
ios
http
basic-authentication
avplayer
【解决方案1】:
我们对类似问题采取了不同的方法,因为我们也必须遵守 HTTP 中的重定向。我们在 cookie 中进行了身份验证,并为整个域设置了它们:
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
kAuthCookieDomain, NSHTTPCookieDomain,
kAuthCookiePath, NSHTTPCookiePath,
kAuthCookieName, NSHTTPCookieName,
kAuthCookieValue, NSHTTPCookieValue,
kAuthCookieDiscard, NSHTTPCookieDiscard,
nil];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:properties];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];