⚖ 许可证
RSAutoWebView 使用 MIT 许可证,详情见 LICENSE 文件。
😬 联系方式:
- WeChat : WhatsXie
- Email : ReverseScale@iCloud.com
- Blog : reversescale.github.io
- Code : github.com/ReverseScal…
EN
For different versions of iOS WebView fragmentation, sorting package, the main function is based on the system version automatically select UI / WK-WebView to load.
Package function:
- Block Method JavaScript <-> Objective-C Interaction.
- Swipe to the top function
- Extended script
- Cookies for WKWebView and UIWebView cache interoperability
- Content rendering interventions
- New Features: Join Tencent VAS · Sonic technology, a framework that claims WebView can be seconds off.
- No need to set up, without plug-ins, to create a base class Inheritance Management Global WebView page. *
🎨 What does the test UI look like?
🚀 Advantage
- Less documents, code concise
- According to the system version automatically choose to use UI / WK WebView, enhance the user experience
- Support both WebView Delegate system callbacks and WebView JavaScriptBridge library callbacks
- The structure of the excellent structure, centralized management through the base class to load the page
- Have a higher custom
🤖 Requirements
- iOS 7+
- Xcode 8+
🎯 Usage Usage
1. RSAutoWebView wrapper method
1.1 Foreign methods
//Use UIWebView - (instancetype)initWithFrame:(CGRect)frame usingUIWebView:(BOOL)usingUIWebView; //Will be transferred WKUIDelegate, WKNavigationDelegate unimplemented callback. @property (weak, nonatomic) id<RSAutoWebViewDelegate> delegate; //Internal use of webView @property (nonatomic, readonly) id realWebView; //Whether you are using UIWebView @property (nonatomic, readonly) BOOL usingUIWebView; //Estimate the progress of webpage loading @property (nonatomic, readonly) double estimatedProgress; @property (nonatomic, readonly) NSURLRequest* originRequest; //Only ios7 above UIWebView can be obtained, WKWebView use the following method. @property (nonatomic, readonly) JSContext* jsContext; //WKWebView way to interact with the web page. - (void)addScriptMessageHandler:(id<WKScriptMessageHandler>)scriptMessageHandler name:(NSString*)name; //back layer - (NSInteger)countOfHistory; - (void)gobackWithStep:(NSInteger)step;
1.2 internal methods
//---- 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; // Clean up the cache - (void)clearCache; - (void)evaluateJavaScript:(NSString*)javaScriptString completionHandler:(void (^)(id, NSError*))completionHandler; // It is not recommended to use this method because it will wait for the execution of the webView internally - (NSString*)stringByEvaluatingJavaScriptFromString:(NSString*)javaScriptString __deprecated_msg("Method deprecated. Use [evaluateJavaScript:completionHandler:]"); // Whether to scale the page by view size defaults to YES @property (nonatomic) BOOL scalesPageToFit;
2. BaseWebViewController base class method
2.1 The basic method
/ * * url request address * isOpen Whether to enable automatic selection of WebView features * Is: usingUIWebView setting is invalid * No: usingUIWebView set whether to use UIWebView * / - (void)loadWebViewWithURL:(NSString *)url autoChoose:(BOOL)isOpen ifCloseAutoChooseUsingUIWebView:(BOOL)usingUIWebView;
2.2 Enhance the method
#pragma mark - Parameters, methods // URL address @property (nonatomic,copy) NSString *url; // Load URL method - (void)reloadRequest:(NSString *)url; // Back to top - (void)scrollToTop; // Image adapted to JavaScript injection - (void)imgAutoFit; // Collapse the keyboard method in WebView - (void)packupKeyboard; // Return method - (void)webViewBackAction:(UIBarButtonItem *)sender; // Clean up the cache - (void)clearCache; #pragma mark - Proxy method /** * Unified wk ui loading state proxy method, combo */ @property (nonatomic,copy) void(^startLoadBlock)(id webView); @property (nonatomic,copy) void(^finishLoadBlock)(id webView); @property (nonatomic,copy) void(^failLoadBlock)(id webView, NSError *error); #pragma mark - WebViewJavascriptBridge JS interaction method // callHandler [OC news to JS] - (void)JSCallHandlerWithFuncName:(NSString *)name Data:(NSDictionary *)dicData; @property (nonatomic,copy) void(^javaScriptCallReturnBlock)(id response); // registerHandler [OC receive JS news] - (void)JSRegisterHandlerWithFuncName:(NSString *)name; @property (nonatomic,copy) void(^javaScriptRegisterReturnBlock)(id response, WVJBResponseCallback responseCallback);
3. Tencent VAS · Sonic seconds to open the WebView framework
3.1 Introduction
VasSonic named after the Sony animated image sound speed kid, is Tencent QQ membership VAS team developed a lightweight high-performance Hybrid framework, focusing on improving the first page of the page loading speed, the perfect support for static straight out of the page and the dynamic straight out of the page, Compatible with offline packages and other programs. Currently QQ members, QQ shopping, QQ wallet, penguins and other businesses have been using e-sports, the average daily PV in more than 120 million, and this number is still rapidly growing.
The first time you access VasSonic, you can request the page resources in parallel while initializing your app and have the ability to load side-edges. When not opening for the first time, the app can quickly load the last time the page resource was dynamically cached in the local page, and then dynamically refresh the page. Tencent mobile QQ through the VasSonic framework makes the first page of the screen consumes less than 1S average time below.
Official open source address: github.com/Tencent/vas…
3.2 The basic method
Quote the header file
// Tencent VAS framework #import "Sonic.h" #import "SonicWebViewController.h" #import "SonicOfflineCacheConnection.h"
Use the jump method
SonicWebViewController *webVC = [[SonicWebViewController alloc]initWithUrl:testTencentURL useSonicMode:YES]; webVC.title = @"VAS·Sonic"; [self.navigationController pushViewController:webVC animated:YES];
Simple to use, efficient, process-safe ~~~ If you have better suggestions, I hope have enlighten me!
Your star is my motivation to keep updating!
📝 CocoaPods update log
- ** 2017.08.22 (tag: 0.9.0): ** </ br>
- Sort open base class method, optimize the realization of the function; </ br>
- Join Tencent open source VasSonic second open WebView framework. </ br>
- ** 2017.04.10 (tag: 0.8.0): ** </ br>
- Add WebViewJavascriptBridge support, add JavaScript <-> Objective-C interaction; </ br> 2.Block callback package; </ br> 3.Cookie cache synchronization mechanism. </ br>
- ** 2016.09.18 (tag: 0.2.5): ** </ br>
- Automatically switch WK / UI-WebView by system version, </ br> 2 functional package. </ br>
- ** 2016.08.26 (tag: 0.1.0): ** </ br>
- Create a manual WebView switch tool. </ br>
⚖ License License
RSAutoWebView uses a MIT license, as detailed in the LICENSE file.
😬 Contact :
- WeChat : WhatsXie
- Email : ReverseScale@iCloud.com
- Blog : reversescale.github.io
- Code : github.com/ReverseScal…