Sometimes it is necessary to call a method or event by clicking on the text or button in the Web page , and we need to make a connection between the Web page and the app.
1. contract with server personnel for a protocol such as ios://
2. When you click on the text or button on the page, jump to the path of this Convention protocol
3. Use the webview proxy method to listen to the URL and determine which operation determines the calling method.
window.location.href = ' Iso://opencamer ';
#pragma mark-uiwebviewdelegate/** This method is called before WebView sends a request, returns Yes, can load the request, returns no, and disables loading of this request */-(BOOL) WebView: ( UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: (Uiwebviewnavigationtype) navigationtype{ NSString *url = Request. url.absolutestring; Nsrange range = [url rangeofstring:@ "ios://"]; if (range.length! = 0) { //Intercept method name nsstring *method = [url substringFromIndex:range.location + range.length]; Convert the method name to SEL type sel selector = nsselectorfromstring (method); [Self performselector:selector withobject:nil]; } return YES;}
Click on UIWebView text to invoke method