As a personal project experience, the use of web+js interaction with deep impression
iOS native app interacts with Web page elements in many ways, JavaScriptCore, interception protocol, third-party framework Webviewjavascriptbridge, Wkwebview after iOS8, etc.
Briefly note the two methods used in the previous development:
1. Hijack page load , intercept requesturl judgment add-in from UIWebView's shouldstartloadwithrequest method, code brief:
-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest:(nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) Navigationtype
{
NSString *URLSTR = [[Request URL] absolutestring];
Loaded URL keyword needs to be the same as the background convention
Nsrange Range_keyword = [urlstr rangeofstring:@ "opengood://"];
if (Range_keyword.length > 0) {
[Self dosomething];
}
return YES;
}
2. IOS7 after the fruit company launched the JavaScriptCore framework, interactive very convenient
Note that the method name of the JS call and so on need to agree with the front-end colleagues, preferably provided to you by the front end.
Shallow said, this way is equivalent to the current Viewcontroller to become a page JS agent, different Web operations can have different JS method and VC above the agent law corresponding,
So for the way the Web load is blocked above, another advantage of JavaScriptCore is to improve the readability of the code ...
Because the project code is related to the company's business is not convenient to paste out, to provide you with two before the investigation of the connection, there is detailed javascriptcore use
Link 1
http://mp.weixin.qq.com/s?__biz=MzAxMzE2Mjc2Ng==&mid=401786074&idx=1&sn= F03d52e7b4f980d694ed4a6b0e808d3b&scene=23&srcid=0309jfhgdiyej4vg1yy3od2t#rd
Link 2
Http://mp.weixin.qq.com/s?plg_nld=1&plg_auth=1&plg_nld=1&plg_dev=1&plg_uin=1&plg_usr=1 &plg_vkey=1&plg_nld=1&plg_uin=1&mid=403853462&plg_nld=1&idx=1&scene=23&plg_ auth=1&__biz=mjm5nzc1mzu2na%3d%3d&plg_dev=1&srcid=0308ayx0hpyq3w7tedwdq8z8&plg_usr=1&sn= F7437fe6fa45e62d86c026efa4aa1645&plg_vkey=1#rd
When many pages involve web interaction, it is necessary to frequently invoke the method associated with Viewcontroller. js
This I wrote a web category, provide download links, welcome to modify and improve
Http://pan.baidu.com/s/1eRSt6p0
iOS Development Uiwebview+javascript Interaction Summary