16六/101
iPhone开发技巧之私有API(7)— 用UIWebView访问BASIC认证的页面
iPhone开发技巧之私有API(7)--- 用UIWebView访问BASIC认证的页面
比如类似下面的 URL,
1 |
http://user:password@www.example.com/ |
需要用户的认证,如果用 UIWebView 访问这样的页面,可以使用下面的委托方法。
1 |
- (void)webView:(id)fp8 resource:(id)fp12 didReceiveAuthenticationChallenge:(id)fp16 fromDataSource:(id)fp20; |
具体参数形式如下。
1 2 3 4 |
- (void)webView:(UIWebView *)webView resource:(NSObject *)resource didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)dataSource; |
利用第3个参数—认证的Challenge对象(NSURLAuthenticationChallenge)的 sender 方法,红色纸认证的信息。如果认证失败,可以从NSURLAuthenticationChallenge 的 previousFailureCount 中取得失败的次数。
1 2 3 4 |
- (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]; } |
相关文章
- iPhone开发技巧之发布篇(7)--- 制作自己的Cydia发布源 - (2012-01-20)
- iPhone开发技巧之发布篇(6)--- 不需Developper认证的真机调试方法 - (2011-12-25)
- iPhone开发技巧之环境篇(11) --- 让Xcode对应多个版本的iOS SDK - (2011-12-03)
- iPhone开发技巧之发布篇(5)--- 在程序中添加广告 - (2011-11-20)
- iPhone开发技巧之环境篇(10)--- 在控制台调试iPhone应用程序 - (2011-11-13)
- iPhone开发技巧之调试篇(3)--- 程序Crash后的调试技巧 - (2011-11-06)
- iPhone开发技巧之环境篇(9)--- Xcode中的注释 - (2011-01-12)
- iPhone开发技巧之数据篇(2)--- iPhone程序中的加密处理 - (2011-01-10)
- iPhone开发技巧之发布篇(4)--- 使用 Ad Hoc 发布自己的应用程序 - (2010-07-22)
- iPhone开发技巧之发布篇(3)--- 你的程序被拒了吗? - (2010-07-19)
- iPhone开发技巧之发布篇(2)--- 税务相关手续 - (2010-07-16)
- iPhone开发技巧之发布篇(1)--- 登录银行信息 - (2010-07-12)
- iPhone开发技巧之工具篇(4)--- 使用afconvert转换WAV文件 - (2010-06-24)
- iPhone开发技巧之私有API(8)--- UIApplication - (2010-06-18)
- iPhone开发技巧之私有API(6)--- 设置UIWebView中的User-Agent - (2010-06-14)
- iPhone开发技巧之私有API(5)--- UISegmentedControl - (2010-06-11)
- iPhone开发技巧之私有API(4)--- UIBarButtonItem - (2010-06-09)
- iPhone开发技巧之私有API(3)--- UIButton - (2010-06-07)
- iPhone开发技巧之数据篇(1)--- 使用正则表达式 - (2010-06-04)
- iPhone开发技巧之私有API(2)--- UITableView - (2010-06-01)
- iPhone开发技巧之私有API(1) --- 设备相关信息 - (2010-05-28)
- iPhone开发技巧之网络篇(5)--- 使用libcurl连接https服务器 - (2010-05-17)
- iPhone开发技巧之网络篇(4)--- 确认网络环境 3G/WIFI - (2010-05-14)
- iPhone开发技巧之网络篇(3)--- 使用NSOperation建立多任务网络连接 - (2010-05-12)
- iPhone开发技巧之网络篇(2)--- Web服务 - (2010-04-20)
2010年12月20日 14:45
很喜欢你的文章,太棒了。。。