打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
iPhone开发技巧之私有API(7)— 用UIWebView访问BASIC认证的页面 | YIFEIYANG

比如类似下面的 URL,

1
http://user:password@www.example.com/

需要用户的认证,如果用 UIWebView 访问这样的页面,可以使用下面的委托方法。

1
- (void)webView:(id)fp8 resource:(id)fp12 didReceiveAuthenticationChallenge:(id)fp16 fromDataSource:(id)fp20;

具体参数形式如下。

1234
- (void)webView:(UIWebView *)webView                             resource:(NSObject *)resource    didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge                       fromDataSource:(WebDataSource *)dataSource;

利用第3个参数—认证的Challenge对象(NSURLAuthenticationChallenge)的 sender 方法,红色纸认证的信息。如果认证失败,可以从NSURLAuthenticationChallenge 的 previousFailureCount 中取得失败的次数。

1234
- (void)webView:(id)webView resource:(id)resource didReceiveAuthenticationChallenge:(id)challenge fromDataSource:(id)dataSource {    NSURLCredential *credential = [NSURLCredential credentialWithUser:@"user" password:@"password" persistence:NSURLCredentialPersistenceForSession];    [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
UIWebView 前进 后退 刷新 取消
使用NSURLConnection请求HTTPS(SSL)接口
JS与iOS之间的通信
利用Objective
gif图片保存和UIwebView显示代码实例 | 开发资源分享区
ios webview清除缓存
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服