无法将特定网站加载到UIWebView:NSURLConnection / CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813)

时间:2014-06-19 07:29:10

标签: ios uiwebview

我已经看到关于证书问题的多个问题,但没有一个答案似乎有效。这是我在尝试运行时遇到的错误: NSURLConnection / CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813)

这是.h文件

#import <UIKit/UIKit.h>

@interface ViewControllerWebAdvisor : UIViewController

@property (strong, nonatomic) IBOutlet UIButton *mainMenuButton;
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) IBOutlet UILabel *loadingLabel;

@end

这是.m文件:

#import "ViewControllerWebAdvisor.h"

@interface ViewControllerWebAdvisor ()

@end

@implementation ViewControllerWebAdvisor

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    _webView.scalesPageToFit = YES;
    NSURL *url = [NSURL URLWithString:@"http://tookOutSiteNameBecauseIConsiderItPersonal.ca"];
    NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:requestURL];

    _mainMenuButton.layer.cornerRadius = 10;
    _mainMenuButton.layer.borderColor=[UIColor blackColor].CGColor;
    _mainMenuButton.layer.borderWidth=2.0f;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    _loadingLabel.text = @"LOADING...";
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    _loadingLabel.text = @"";
}

@end

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

从Apple文档中,您可以通过以下代码禁用证书检查。在appDelegate.m中添加它们

@implementation NSURLRequest(DataController) 
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host 
{ 
return YES; 
} 
@end 

此链接是Apple文档https://developer.apple.com/library/ios/technotes/tn2232/_index.html#//apple_ref/doc/uid/DTS40012884-CH1-SECINTRODUCTION

希望有所帮助