WKWebView初探侦
5628 ワード
#import "ViewController.h"
#import
#import
@interface ViewController ()
@property (strong, nonatomic) WKWebView *wkWebView;
@end
/**
*
* JSContext: JavaScript
* JSValue:JavaScript Objective-C
* JSManagedValue:
* JSVirtualMachine: ,
* JSExport: , ,
*/
@implementation ViewController
#pragma mark ==================== ====================
- (WKWebView *)wkWebView
{
if (!_wkWebView)
{
//
WKPreferences *preferences = [[WKPreferences alloc] init];
//
preferences.minimumFontSize = 0;
// JavaScript
preferences.javaScriptEnabled = YES;
// , JavaScript
preferences.javaScriptCanOpenWindowsAutomatically = NO;
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
configuration.preferences = preferences;
_wkWebView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:configuration];
}
return _wkWebView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:self.wkWebView];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
[_wkWebView loadRequest:request];
}
#pragma mark ==================== WKNavigationDelegate ====================
//// , , , ,
//- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
//{
//
//}
//
////
//- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
//{
//
//}
//
////
//- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation
//{
// NSLog(@"%s", __func__);
//}
//
////
//- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation
//{
//
//}
//
////
//- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
//{
//
//}
//
////
//- (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation
//{
//
//}
//
////
//- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
//{
//
//}
//
////
//- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
//{
//
//}
//
//
//// , block
//- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler
//{
//
//}
//
////
//- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView API_AVAILABLE(macosx(10.11), ios(9.0))
//{
//
//}
#pragma mark ==================== WKUIDelegate ====================
// tab, . WKWebView, 、 、window 。 , , webview 。
//- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
//{
//
//}
//
//// WKWebView
//- (void)webViewDidClose:(WKWebView *)webView API_AVAILABLE(macosx(10.11), ios(9.0))
//{
//
//}
//
//
////JavaScript alert message alert completionHandler()
//- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
//{
//
//}
//
//
////JavaScript confirm confirm js , block
//- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler
//{
//
//}
//
//
////JavaScript prompt prompt js block
//- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler
//{
//
//}
//- (BOOL)webView:(WKWebView *)webView shouldPreviewElement:(WKPreviewElementInfo *)elementInfo API_AVAILABLE(ios(10.0))
//{
//
//}
//
//- (nullable UIViewController *)webView:(WKWebView *)webView previewingViewControllerForElement:(WKPreviewElementInfo *)elementInfo defaultActions:(NSArray> *)previewActions API_AVAILABLE(ios(10.0))
//{
//
//}
//
//
//- (void)webView:(WKWebView *)webView commitPreviewingViewController:(UIViewController *)previewingViewController API_AVAILABLE(ios(10.0))
//{
//
//}
//
//
//- (void)webView:(WKWebView *)webView runOpenPanelWithParameters:(WKOpenPanelParameters *)parameters initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSArray * _Nullable URLs))completionHandler API_AVAILABLE(macosx(10.12))
//{
//
//}
@end