Ios-wkwebview use

Source: Internet
Author: User

Using code: You can paste directly into your project
. h

#import"BaseViewController.h"@interface LinkNewsController : BaseViewController/** 新闻链接 */@property (nonatomic, strong) NSString *link;@end

. m

#import <WebKit/WebKit.h> #import "MBProgressHUD.h"  @interface linknewscontroller () <wknavigationdelegate>{    //MasksMbprogresshud *_MB;}//Page view@property(nonatomic,Strong) Wkwebview *wkwebview;@end @implementation linknewscontroller #pragma mark-Lazy loading-(Wkwebview *) wkwebview{if(_wkwebview = =Nil{_wkwebview = [[Wkwebview alloc] Initwithframe:cgrectmake (0, -, Kscreenwidth, kscreenheight- -)];NSLog(@"web link-->link:%@", Self. Link);nsurlrequest*request = [nsurlrequestrequestwithurl:[NsurlURLWithString: Self. Link]]; [_wkwebview setnavigationdelegate: Self];    [_wkwebview Loadrequest:request]; }return_wkwebview;}#pragma mark-View loading- (void) Viewdidload {[SuperViewdidload];additional setup after loading the view.[ Self. ViewAddsubview: Self. Wkwebview];}#pragma mark-wknavigationdelegate//Start loading-(void) WebView: (Wkwebview *) WebView didstartprovisionalnavigation: (wknavigation *) navigation{NSLog(@"Didstartprovisionalnavigation"); _MB = [Mbprogresshud showhudaddedto: Self. Navigationcontroller. ViewAnimated:YES];    [_mb Setmode:mbprogresshudmodeindeterminate]; [_mb setlabeltext:@"Loading ..."];}//onboarding Success-(void) WebView: (Wkwebview *) WebView didfinishnavigation: (wknavigation *) navigation{NSLog(@"didfinishnavigation__"); [_MB Hide:YES];}//Load Failure-(void) WebView: (Wkwebview *) WebView didfailnavigation: (wknavigation *) Navigation Witherror: (Nserror*) error{NSLog(@""); [_MB Hide:YES];}

The difference between UIWebView and Wkwebview
Wkwebview is faster (taking up memory may only have UIWebView 1/3~1/4), without caching. More carefully split the methods in the Uiwebviewdelegate.
The Wkwebview is a lightweight uiwebview.

Ios-wkwebview use

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.