在您的 .h 文件中
// Needed for UIViewController, UIWebViewDelegate, and UIView
#import <UIKit/UIKit.h>
// Needed for WKNavigationDelegate and WKUIDelegate
#import <WebKit/WebKit.h>
// Used to define the webView property below
#import "QSWebViewAdapter.h"
// The main web view that is set up in the viewDidLoad method.
@property (nonatomic) UIView <QSWebViewAdapter> *webView;
在您的 .m 文件中
// Required for calls to UIWebView and WKWebView to "see" the QSUIWebView and
QSWKWebView categories
#import "UIWebView+QSUIWebView.h"
#import "WKWebView+QSWKWebView.h"
#import "QSWebViewFactory.h"
- (void)viewDidLoad
{
[super viewDidLoad];
// If it is present, create a WKWebView. If not, create a UIWebView.
_webView = GetQSWebViewWithFrame([[self view] bounds]);
// Add the webView to the current view.
[[self view] addSubview: [self webView]];
// Assign this view controller as the delegate view.
// The delegate methods are below, and include methods for UIWebViewDelegate, WKNavigationDelegate, and WKUIDelegate
[[self webView] setDelegateViews: self];
// Ensure that everything will resize on device rotate.
[[self webView] setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[self view] setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
// Just to show *something* on load, we go to our favorite site.
[[self webView] loadRequestFromString:@"http://www.google.com"];
}