简体   繁体   English

WKWebView白屏(Objective-C)

[英]WKWebView White Screen (Objective-C)

Still having some trouble with Webkit. 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). 从昨天早上整理出我的错误之后,我遇到了一个全新的问题,从113到直接崩溃(iOS开发新手,正式用C ++训练,非常生疏哈哈)。

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. 我终于得到了一些不会崩溃的代码,我觉得我对Objective-C / iOS Dev一般有更好的把握 - 只有一个问题......它没有加载。

WebView.h 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 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? 我怀疑它与视图/ UIView和加载有关? I'm just not sure how to pinpoint what I'm doing wrong exactly. 我只是不确定如何确切地指出我做错了什么。

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. 您的网址未使用“https”安全协议,因此您需要在Info.plist文件中添加以下密钥,以便在网络视图中加载您的网址。

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Also you are doing one more wrong thing with webview. 你也在用webview做一件错事。

This doesen't proper way to add webview in self.view . 这不是在self.view添加webview正确方法。

self.view = webView; 

updated this line with; 更新此行;

[self.view addSubview:webView];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM