ios - 无法让 WebKit 显示网页
问题描述
我正在尝试研究如何在我的 IOS 应用程序中显示网页。我试图仔细遵循我能找到的信息。这是我正在使用的:
@implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.productURL = @"http://google.com/";
NSURL *url = [NSURL URLWithString:self.productURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
_webView = [[WKWebView alloc] initWithFrame:self.view.frame];
[_webView loadRequest:request];
_webView.frame = CGRectMake(self.view.frame.origin.x+50,self.view.frame.origin.y+50, self.view.frame.size.width-100, self.view.frame.size.height-200);
printf("\nReady to add the Subview");
self.view.backgroundColor = [UIColor blueColor];
[self.view addSubview:_webView];
printf("\nSubView has been added");
}
@end
框架在上面是偏移的,所以我可以给它上色并看到子视图将被定位在那里。据我了解,该网页应该出现在子视图中,但我只是得到一个空白页面。
我还将 NSExceptionDomains 字典添加到我的 Info.plist 并添加了 google.com,其中包含一个字典,其中 NSIncludesSubdomains 设置为 true,NSExceptionAllowsInsecureHTTPLoads 设置为 true,认为这可能是问题所在,但无济于事。我已经尝试了几个网址和同样的事情。
我怎样才能找出正在发生的事情并解决它?
解决方案
我发现了问题!显然,我需要将键“App Transport Security Settings”作为字典添加到我的 Info.plist 中,并将键“Allow Arbitrary Loads”添加为 true。它现在显示!
我以前找不到这个,但是当我找到并添加它时,它与上面的代码一样工作得很好。
推荐阅读
- c# - 如何从我的控制台应用程序打开多个 http 链接?
- excel - 具有更高权限的 VBA GetObject(以其他用户身份运行)
- c# - 使用 C# 向单元格错误添加 Sumif 公式
- sql-server - SQL Server 如何在 char 中实际存储俄罗斯符号?
- javascript - 跨域读取阻塞 (CORB) 阻止跨域响应
- php - 如何“清理”从 file() 读取的字符串
- sql - 这段代码有什么问题
- c++ - 无法打开网络摄像头 GStreamer 给出错误(openCV)
- c# - 如何使用 Firebird 服务器远程连接数据库文件
- ios - iOS GPUImage - 色度键控 GPUImageChromaKeyBlendFilter 不适用于用白色替换图像上的黑色/灰色