【发布时间】:2019-03-26 15:46:15
【问题描述】:
我正在尝试研究如何在我的 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,认为这可能是问题所在,但无济于事。我已经尝试了几个网址和相同的东西。
我怎样才能找出正在发生的事情并解决它?
【问题讨论】:
-
可能不是问题,但我会在加载请求之前将视图添加到其超级视图中。如果 Web 视图没有安装在任何视图中,则没有理由加载请求。
标签: ios objective-c webkit mobile-webkit