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.