(59) UIWebView Simple Browser implementation of iOS Network Foundation

Source: Internet
Author: User

"UIWebView Web Browser"

The WebView Loadrequest method allows you to send a request to display the appropriate Web site, for example:

    Nsurl *url = [Nsurl urlwithstring:@ "http://m.baidu.com"];    Create request data    nsurlrequest *request = [Nsurlrequest requestwithurl:url];    Send request to Server    [Self.webview loadrequest:request];

By using Searchbar, you can implement the input of the URL, Searchbar has a delegate property can set the controller as its agent, the following implementation of a simple browser.

The first is to invoke the proxy method to listen for the search button:

-(void) searchbarsearchbuttonclicked: (Uisearchbar *) searchbar{        [Self.view Endediting:yes];        [Self searchWithNSStringUrl:searchBar.text];    }

Then realize the parsing of the search bar information, note that there is no logical way to complete the http://.

You can use the Nsstringfromrange method to find the substring position of a string by judging if the location member of range is equal to Nsnotfound to determine if the match fails.

-(void) Searchwithnsstringurl: (NSString *) surl{        nsrange range = [surl rangeofstring:@ "/http"];        NSLog (@ "range =%@", Nsstringfromrange (range));        if (range.location = = nsnotfound) {                NSString *head = @ "/http";        sURL = [head stringbyappendingstring:surl];            }        Nsurl *url = [Nsurl Urlwithstring:surl];    Create request data    nsurlrequest *request = [Nsurlrequest requestwithurl:url];    Send request to Server    [Self.webview loadrequest:request];    }

Directly determine whether a string begins with a string directly using the NSString Hasprefix: method.

The implementation of forward and backward:

Binds the button's forward and backward events and buttons directly.

Some details:

1. You should disable the button when you cannot go back and forward, and the different pages are connected through the linked list.

The way of judging: by judging the list of WebView, you can also judge by CanGoBack and CanGoForward two bool variables.

2. The address bar should change with the content of the Web page by getting the URL of the webview and converting it to a string using the Absolutestring method:

-(void) Webviewdidstartload: (UIWebView *) webview{    nsurl *url = WebView.request.URL;    NSString *surl = [url absolutestring];    Self.searchBar.text = sURL;}

Using HTML:

PhoneGap is a set of frameworks developed based on HTML 5 that can be used to develop applications as long as they are web pages, but not native hardware.

The benefit is the ability to develop multiple platform applications at once.


"Loading files with UIWebView"

Can be loaded by bundle or sandbox.

The URL of the incoming file can load a variety of contents such as Doc, txt, picture, PDF, and so on.

For example, read into a PDF:

Nsurl *fileurl = [[NSBundle mainbundle] urlforresource:@ "english.pdf" withextension:nil]; Nsurlrequest *request = [Nsurlrequest Requestwithurl:fileurl]; [Self.webview Loadrequest:request];
You can also use Datadetectortypes to set the type of text you want to highlight: such as phone, address, mailbox, etc.

_webview.datadetectortypes = Uidatadetectortypeall;

"Loading HTML with UIWebView"

[Self.webview loadhtmlstring:@ "
This feature can be used to delete ads and other functions.


"Why UIWebView can load files"

MIME type is an Internet standard in which the server tells the browser which plug-in to use to read related files in the transmitted data, and MIME types can contain data such as video, images, text, and so on.

The network transmits data through a binary data stream, and the client can know how to process the received data through MIME type.

(59) UIWebView Simple Browser implementation of iOS Network Foundation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.