To establish a network connection step
Identify URLs: Identify the network resources you want to access
Establishing a network request (URLRequest)
Request Send (Nsurlconnection, nsurlsession) to the server
Processing the data returned by the server (proxy, block callback)
UIWebView
UIWebView is an iOS built-in browser control that lets you browse Web pages, open documents, and more.
Ability to load files in HTML, htm, PDF, docx, TXT and other formats.
The system comes with a safari browser that is implemented through UIWebView.
Before IOS7, UILabel, Uitextfield, and Uitextview used WebKit in some way in the background for text layout and rendering.
Rendering: It is the final process of CG, which makes the design content into the final or the animation.
UIWebView Walkthrough
* Loading Baidu Homepage
1. Identify the network resources you want to access-url
Nsurl *url = [Nsurl urlwithstring:@ "http://www.baidu.com"];
2. Create a network request
Nsurlrequest *request = [Nsurlrequest Requestwithurl:url];
3.UIWebView Load Network Request
[Self.webview Loadrequest:request];
* To achieve Baidu search
-(void) searchbarsearchbuttonclicked: (Uisearchbar *) Searchbar
{
NSString *str = Searchbar.text;
1. Decide whether to start with http://, if not, use Baidu Search
if (![ STR hasprefix:@ "/http"]) {
str = [NSString stringwithformat:@ "http://www.baidu.com/s?word=%@", str];
}
2. In the URL, if you include the string in the text, you need to convert the string to a percent semicolon format
Nsurl *url = [Nsurl urlwithstring:[str strbyaddingpercentescapesusingencoding:nsutf8stringencoding];
......
}
UIWebView Loading files
UIWebView can also load bundles or files in the sandbox
about MIME type
The MIME English whole "Multipurpose Internet Mail Extensions" Multipurpose Internet Email extension is an Internet standard that was first applied to the e-mail system and later applied to the browser.
The server tells the browser the amount of multimedia data sent by explaining the MIME type of the multimedia data, so that the browser knows what the MP3 file is, which is the Shockwava file, and so on.
The server puts the MIME identifier in the transmitted data to tell the browser which plug-in to use to read the relevant file.
* The network can transfer data in any format by means of a binary data stream.
* The client can know how to process the received data through MIME type.
URL & Request send requests to the server
Response response, the server tells the client about the binary data that is returned.
the communication between JS and the Web
Gets the URL of the current page
NSString *url=[_webview stringbyevaluatingjavascriptfromstring:@ "Document.location.href"];
Gets the title of the current page
NSString *title = [_webview [email protected] "document.title"];
Submit Form
[_webview stringbyevaluatingjavascriptfromstring:@ "Document.form[0].submit ();"];
custom protocols interact with OC
<a href= "js-call://loadurl/m.baidu.com" > Baidu a bit, you know! </a>
Realize the WebView
-WebView:shouldStartloadViewRequest:navigationType:
Proxy method
This proxy method will be triggered before WebView will jump
Process steps:
Intercept the URL string to jump
Determine whether a custom protocol
If it is a custom protocol, split the remaining contents of the URL
Dynamically generates the SEL and passes the remainder as a parameter to the method
Handling of warning messages
# pragma clang diagnostic push
#pragma clang diagnostic ignored "-warc Performselector-leaks"
[Self performselector:fund withobject:[array[1]];
#pragma clang diagnostic pop
JS Injection
[WebView stringbyevaluatingjavascriptfromstring:@ "var script = document.createelement (' script ');"
"Script.type = ' text/javascript ';"
"Script.text = \" Function myFunction () {"
"var field = document.getelementsbyname (' word ') [0];"
"Field.value= ' IPhone ';"
"Document.forms[0].submit ();"
"}\";"
"document.getElementsByTagName (' head ') [0].appendchild (script);"];
[WebView stringbyevaluatingjavascriptfromstring:@ "myFunction ();"];
Introduction and usage of UIWebView in iOS