Reputation: 29
Still having some trouble with Webkit. After sorting out my error from yesterday morning, I have encountered a whole new slue of them ranging from 113 to straight up crashes (really new to iOS dev, formally trained in C++ and very rusty haha).
I've finally got some code that doesn't crash and I feel like I'm definitely getting a better grasp on Objective-C/iOS Dev in general - there's just one issue... It doesn't load.
WebView.h
#ifndef WebView_h
#define WebView_h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Webkit/Webkit.h>
@interface ViewController: UIViewController;
@property (nonatomic, strong) IBOutlet WKWebView *webView;
@property (nonatomic, strong) IBOutlet UIView *view;
@end
#endif WebView_h
WebView.m
@implementation ViewController
@synthesize webView;
-(void) viewDidLoad {
[super viewDidLoad];
webView = [[WKWebView alloc] initWithFrame:[[self view] bounds]];
NSURL *url = [NSURL URLWithString:@"http://www.penelopeperu.com/"];
NSURLRequest *urlReq = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlReq];
self.view = webView;
}
@end
I suspect it has something to do with the view / UIView and loading? I'm just not sure how to pinpoint what I'm doing wrong exactly.
Upvotes: 2
Views: 6628
Reputation: 5823
Your url is not using "https" security protocol, so you need to add following key in Info.plist file to allow load your url in web view.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Also you are doing one more wrong thing with webview.
This doesen't proper way to add webview
in self.view
.
self.view = webView;
updated this line with;
[self.view addSubview:webView];
Upvotes: 3