I'm trying to work out how to display a web page inside my IOS app. I've tried to carefully follow what information I can find. Here is what I'm using:
@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
The frame is offset in the above so I could color it and see that the subview would be positioned there. The web page should appear in the subview as I understand it, but I just get a blank page.
I also added NSExceptionDomains dictionary to my Info.plist and added google.com with it having a dictionary contains NSIncludesSubdomains set to true and NSExceptionAllowsInsecureHTTPLoads set to true thinking that might be the problem, but to no avail. I've tried several urls and same thing.
How can I find out what is happening and fix it?
I found the problem! Apparently I needed to add the key 'App Transport Security Settings' as a dictionary to my Info.plist and add the key 'Allow Arbitrary Loads' as true to that. It now displays!
I could not find this before, but when I did and added it, it worked fine with the code just as above.