• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UIWebView 身份验证在 iOS 7.1 中不再起作用

[复制链接]
菜鸟教程小白 发表于 2022-12-12 21:44:48 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

自从升级到 iOS 7.1 后,我的应用程序出现了一些严重问题。 webview 和身份验证挑战运行良好。由于我已经升级,webview 不再显示内容。身份验证似乎工作正常,因为我通过调试 + NSLog 获得了正确的值,所以无效的凭据不是问题(检查了大约 10 次)。在 webview 使用有效凭据重新加载页面后,仍然没有显示任何内容。这是我的代码:

- (void)viewDidLoad
{
    _authed = NO;
    [self.webView loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString"xxx"]]];
}

- (BOOL)webViewUIWebView *)webView shouldStartLoadWithRequestNSURLRequest *)request navigationTypeUIWebViewNavigationType)navigationType;
{
    NSLog(@"Did start loading: %@ auth:%d", [[request URL] absoluteString], _authed);

    if (!_authed) {
        _authed = NO;
        [[NSURLConnection alloc] initWithRequest:request delegate:self];
        return NO;
    }
    return YES;
}

- (void)connectionNSURLConnection *)connection willSendRequestForAuthenticationChallengeNSURLAuthenticationChallenge *)challenge
{

    if ([challenge previousFailureCount] > 0) {

    }
    else
    {

        NSURLCredential *credential = [NSURLCredential credentialWithUser"xxx"
                                                                 password"xxx"
                                                              persistence:NSURLCredentialPersistencePermanent];
        [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
    }

}

- (void)connectionNSURLConnection *)connection didReceiveAuthenticationChallengeNSURLAuthenticationChallenge *)challenge;
{
    NSLog(@"got auth challange");

    if ([challenge previousFailureCount] == 0) {
        _authed = YES;
        [[challenge sender] useCredential:[NSURLCredential credentialWithUser"xxx" password"xxx"  persistence:NSURLCredentialPersistencePermanent] forAuthenticationChallenge:challenge];
    }
    else
        [[challenge sender] cancelAuthenticationChallenge:challenge];
}

- (void)connectionNSURLConnection *)connection didReceiveResponseNSURLResponse *)response;
{
    NSLog(@"received response via nsurlconnection");

    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString: @"xxx"]];

    [self.webView loadRequest:urlRequest];
    _authed = YES;
}


- (BOOL)connectionShouldUseCredentialStorageNSURLConnection *)connection;
{
    return NO;
}

NSLog 输出:

2014-04-17 12:23:20.418 Test[510:60b] Did start loading: xxx auth:0

2014-04-17 12:23:20.704 Test[510:60b] received response via nsurlconnection

2014-04-17 12:23:20.710 Test[510:60b] Did start loading: xxx auth:1

提前致谢。



Best Answer-推荐答案


您可以在 url 而不是请求 header 中通过身份验证,请尝试而不是 BASE_URL: NSString* urlString = [NSString stringWithFormat"%@//%@:%@@%@",@"http:",userName,password,myUrl]

关于ios - UIWebView 身份验证在 iOS 7.1 中不再起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23130780/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap