[blocked] The page at *.html was

2017-11-09  本文已影响0人  luckycoder

//当webView 加载的html 页面中有加载完 需要运行的js 会报错 [blocked] The page at *.html was not allowed to run insecure content from
//原因为 客户端加载完运行的js 请求的https URL 为不可信任的地址 被webView拦截
//1.换成 NSURLConnection 请求 接口即可 2.请求的https URL 为可信任

解决办法 用NSURLSession 进行重定向的时候会报错
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    //会引起错误的请求方式
    /* 
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
                __weak typeof(self) weakSelf = self;
                NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                
                }];
    [task resume];
    */
    //临时解决方案
    NSURLConnection *connection =[[NSURLConnection alloc] initWithRequest:request delegate:self];
    [connection start];
    return NO;


}


上一篇下一篇

猜你喜欢

热点阅读