IOS-WKWebView usage

Source: Internet
Author: User

IOS-WKWebView usage

Code: You can directly paste it into your project.
. H

# Import "BaseViewController. h" @ interface LinkNewsController: BaseViewController/** news link */@ property (nonatomic, strong) NSString * link; @ end

. M

# Import
  
   
# Import "MBProgressHUD. h" @ interface LinkNewsController ()
   
    
{// Mask MBProgressHUD * _ MB;} // webpage view @ property (nonatomic, strong) WKWebView * WKWebView; @ end @ implementation LinkNewsController # pragma mark-lazy loading-(WKWebView *) WKWebView {if (_ WKWebView = nil) {_ WKWebView = [[WKWebView alloc] initWithFrame: CGRectMake (0, 64, kScreenWidth, kScreenHeight-64)]; NSLog (@ "webpage link --> link: % @", self. link); NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: self. link]; [_ WKWebView setNavigationDelegate: self]; [_ WKWebView loadRequest: request];} return _ WKWebView;} # pragma mark-view loading-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. [self. view addSubview: self. WKWebView] ;}# pragma mark-WKNavigationDelegate // start loading-(void) webView :( WKWebView *) webView progress :( WKNavigation *) navigation {NSLog (@ "didStartProvisionalNavigation "); _ MB = [MBProgressHUD showHUDAddedTo: self. navigationController. view animated: YES]; [_ MB setMode: MBProgressHUDModeIndeterminate]; [_ MB setLabelText: @ "loading... "];} // load succeeded-(void) webView :( WKWebView *) webView didFinishNavigation :( WKNavigation *) navigation {NSLog (@" didFinishNavigation _ "); [MBProgressHUD hideAllHUDsForView: self. navigationController. view animated: YES];} // loading failed-(void) webView :( WKWebView *) webView didFailNavigation :( WKNavigation *) navigation withError :( NSError *) error {NSLog (@ ""); [MBProgressHUD hideAllHUDsForView: self. navigationController. view animated: YES];}
   
  

Difference between UIWebView and WKWebView
WKWebView is faster (the memory usage may be only 1/3 of that of UIWebView ~ 1/4), no cache, more detailed splitting of methods in UIWebViewDelegate.
WKWebView is a lightweight UIWebView.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.