Chapter 14

Programming the Canvas

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • Identifying the IOS user agent
  • Drawing rectangles and other shapes
  • Drawing images onto a canvas

The unique platform capabilities of the IOS enable developers to create innovative applications inside Safari that go beyond the normal “web app” fare. Safari’s support for the canvas element opens drawing and animation capabilities in an ordinary HTML page that were previously available only by using Flash or Java. The canvas element is part of the Web Hypertext Application Technology Working Group (WHATWG) specification for HTML 5.0 (or HTML5).

However, after you begin to open up these capabilities you need to be sure that you are working with an IOS device rather than a standard desktop browser that may not provide HTML5 support. Consequently, you need to be able to identify the user agent for IOS devices.

IDENTIFYING THE USER AGENT

When you are trying to identify the capabilities of the browser requesting your website or application, you generally should avoid detecting the user agent; instead you should use object detection. However, if you are developing an application designed exclusively for iPhone or need to be certain of the browser being used then user agent detection is a valid option. Therefore, this chapter assumes you are creating a Safari-specific application.

The Safari user agent string for iPhone closely resembles the user agent for Safari on other platforms. However, it contains an iPhone platform ...

Get Beginning iOS Application Development with HTML and JavaScript® 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.