UIWebView Seamless Switch to Wkwebview

Source: Internet
Author: User


Wkwebview is the new web browsing view of IOS8


Advantage : Loading speed is almost one times higher than UIWebView, memory use above, but less half.

Disadvantages : Wkwebview does not support caching and Nsurlprotocol interception.


I recommend that if you use a page that is not high on the cache, the user experience will improve a lot.


Since the project was previously UIWebView and compatible with IOS8 before. So I created a new class Imywebview you can seamlessly upgrade to Wkwebview if you replace UIWebView globally.


The APIs in IMYWebView.h automatically support UIWebView and Wkwebview internally,

title,estimatedprogress is the new API that I think is more useful in Wkwebview

@interface imyvkwebview:uiview///using uiwebview-(instancetype) initWithFrame: (CGRect) frame Usinguiwebview: (BOOL) Usinguiwebview; @property (weak,nonatomic) id<imyvkwebviewdelegate> delegate;///Internal Use Webview@property ( Nonatomic, ReadOnly) ID realwebview;///Whether you are using Uiwebview@property (nonatomic, readonly) BOOL usinguiwebview;/// Estimated page Load Progress @property (Nonatomic, readonly) double estimatedprogress; @property (nonatomic, readonly) nsurlrequest * Originrequest;///back Layer-(Nsinteger) countofhistory;-(void) Gobackwithstep: (nsinteger) step;///----UI or WK Api@property (nonatomic, ReadOnly) Uiscrollview *scrollview;-(ID) loadrequest: (Nsurlrequest *) request;-(ID) loadHTMLString: (NSString *) string BaseURL: (Nsurl *) BaseURL; @property (nonatomic, readonly, copy) NSString *title;@ Property (Nonatomic, ReadOnly) nsurlrequest *currentrequest; @property (nonatomic, readonly) Nsurl *url; @property ( Nonatomic, ReadOnly, getter=isloading) bool loading; @property (nonatomic, readonly) bool CanGoBack; @property (nonatomIC, ReadOnly) BOOL cangoforward;-(ID) goback;-(ID) goforward;-(ID) reload;-(ID) reloadfromorigin;-(void) stoploading;- (void) Evaluatejavascript: (NSString *) javascriptstring Completionhandler: (void (^) (ID, Nserror *)) Completionhandler //////Do not recommend this method because it will wait for the WebView execution result internally-(NSString *) stringbyevaluatingjavascriptfromstring: (NSString *) Javascriptstring __deprecated_msg ("Method deprecated. Use [Evaluatejavascript:completionhandler:] ");/////whether to scale the page according to the view size default is Yes@property (nonatomic) BOOL scalespagetofit;@ End


Code address

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UIWebView Seamless Switch to Wkwebview

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.