Chapter 11. Web Views

A web view is a UIView subclass whose primary purpose is to act as a web browser; therefore, it knows how to fetch resources from the Internet, and it understands and can render text in HTML, along with associated information coded as CSS and JavaScript. Thus it is an asynchronous network communication engine on the one hand, and a powerful engine for layout, animation, and media display on the other.

All of that power comes “for free” with a web view. It gives your app a browser interface, comparable to Mobile Safari; you can just stand back and let it do its work. You don’t have to know anything about networking. Links and other ancillary resources work automatically. If your web view’s HTML refers to an image, the web view will fetch it and display it. If the user taps on a link, the web view will fetch that content and display it; if the link is to some sort of media (a sound or video file), the web view will allow the user to play it.

A web view also knows how to display various other types of content commonly encountered as Internet resources. For example, a web view is an excellent way to display PDF files. It can also display documents in such formats as .rtf, Microsoft Word (.doc and .docx), and Pages. (A Pages file that is actually a bundle must be compressed to form a single .pages.zip resource.)

Warning

A web view should also be able to display (compressed) .rtfd files, but as of this writing, it can’t. Apple suggests that you convert to an attributed ...

Get Programming iOS 8 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.