UIWebView seamlessly switches to WKWebView and uiwebviewwkwebview

Source: Internet
Author: User

UIWebView seamlessly switches to WKWebView and uiwebviewwkwebview

WKWebView is a new Web View added by IOS8.


Advantage: The loading speed is almost doubled than that of UIWebView, and the memory usage is half as high as above.

Disadvantage: WKWebView does not support caching or NSURLProtocol interception.


I recommend that you use pages that are not highly cached, and the user experience will be improved a lot.


Since UIWebView is used in the project and is compatible with machines before ios8. So I created a new class IMYWebView. You can seamlessly upgrade it to WKWebView by replacing UIWebView globally.


APIs in IMYWebView. h automatically support UIWebView and WKWebView internally,

Title, estimatedProgress is a new API that I think is useful in WKWebView.

@ Interface IMYVKWebView: UIView // use UIWebView-(instancetype) initWithFrame :( CGRect) frame usingUIWebView :( BOOL) usingUIWebView; @ property (weak, nonatomic) id <strong> delegate; /// internally used webView @ property (nonatomic, readonly) id realWebView; // whether UIWebView @ property (nonatomic, readonly) BOOL usingUIWebView is being used; /// estimate the webpage loading 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; /// this Method is not recommended because it waits for the execution result of webView internally-(NSString *) stringByEvaluatingJavaScriptFromString :( NSString *) javaScriptString _ deprecated_msg ("Method deprecated. use [evaluateJavaScript: completionHandler:] "); // whether to scale the Page Based on The View Size. The default value is YES @ property (nonatomic) BOOL scalesPageToFit; @ end


Code address

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.