APPENDIX

Exercise Answers

CHAPTER 1

1. A native app runs executable code on the device and is installable through the App Store. A web app runs inside of Safari on IOS and requires no installation onto the device. A native app is written in Objective-C whereas a web app is written using HTML, CSS, JavaScript, and AJAX.

2. Yes. A user can add a web app to the Home screen through the Safari menu.

3. A finger can emulate normal mouse actions — a click, scroll, and mouse move. However, it also has additional touch-related actions that have no mouse equivalent, including a tap, flick, drag, and pinch.

CHAPTER 2

1. Use var to declare a keyword, such as var index = 0;.

2. A local variable is accessible only inside a JavaScript function, whereas a global variable is accessible anywhere in the document.

3. The = assigns a value whereas the == operator is used to compare whether two values are equal.

4. !=

5. The basic structure of a for loop looks something like:

for (var i=0;i<10;i++) 
{ 
   // Do something here
}

6. Use arguments.length to determine to the total number of parameters passed to a function.

7. No. JavaScript treats an empty string as a different value than null.

CHAPTER 3

1. The node is the basic component of the DOM.

2. False. A DOM hierarchy is not exactly the same as the element hierarchy that is shown in an HTML document. For example, attributes and text content of an element are child nodes of that element rather than being a descriptor of it.

3. A NodeList is a collection of nodes.

4. A document fragment is a temporary “off-line” document that you can use to create and modify part of a tree before you add the fragment to the actual DOM tree.

CHAPTER 4

1. The advantage of using a mobile framework like jQuery Mobile is that it automates many of styling and scripting parts of your mobile app. You can even optimized it for both iPhone and iPad devices without any changes on your part.

2. No, you can store them in separate div elements in the same page, demarking them with a data-role="page" attribute.

3. You can link to another virtual page by referencing the destination page’s unique id in an href attribute, prefixed with a # symbol (href="#mypage").

CHAPTER 5

1. No, IOS devices do not support Adobe Flash.

2. A viewport is a rectangular area of screen space within which a web page is displayed. It determines how content is displayed and scaled to fit onto the iPhone or iPad.

3. The device-width constant is treated as 320px on an iPhone and 1024px on an iPad.

4. Columns make your page readable like a newspaper and help you avoid wide blocks of text that cause users to horizontally scroll left and right to read.

5. It is recommended that your iPad media query look like the following:

<link 
  media="only screen and (min-device-width: 768px) and (max-device-width: 1024px)"
  type="text/css" rel="stylesheet" href="iPad.css" />

CHAPTER 6

1. Edge-to-edge navigation lists are the standard way to present list or hierarchical information.

2. It is generally recommended that you size your UI element by 40 pixels or more for ease of touch.

3. False. You won’t find it on an IOS device.

4. False. Web apps have no control over screen orientation. Therefore, your design must accommodate both portrait and landscape orientations.

CHAPTER 7

1. False. Your iPad web app should include a viewport meta tag.

2. Trick question. They are equally important in nearly every case, so your design should account for both.

3. You can use iScroll library or other similar open-source solutions to overcome this Safari on IOS limitation.

CHAPTER 8

1. Safari on IOS supports most of the properties that are prefixed with -webkit- before their names.

2. For a normal website, -webkit-text-size-adjust: auto is recommended for improving the readability of text. However, if you are developing an application, you almost always want to use -webkit-text-size-adjust: none.

3. Use the -webkit-border-image property.

CHAPTER 9

1. You can link to a div, ul, or form container in the same page by referencing its id as an anchor (for example, #mylist).

2. You can create a link and add target="_replace" as an attribute. iUI loads the items from the URL replacing the current link.

3. The answer ultimately depends on your target audience, but generally speaking, you need to design your app using a framework that is compatible for both iPhone and iPad — and, depending on your audience, Android as well.

CHAPTER 10

1. Mouse emulation, touch, and gesture events.

2. No, there are several touch interactions that are handled for you by default by Safari on IOS. These include flick-scrolling, zoom pinching and unpinching, and one-finger panning (or scrolling).

3. The body element’s onorientationchange event.

CHAPTER 11

1. The context object, obtained from the canvas object’s getContext() method.

2. To create a reflection, use the -webkit-box-reflect property.

3. The save() method saves a snapshot of the canvas, which can then be retrieved using the restore() method. The save() and restore() methods enable you to return to a default drawing state with minimal additional code and without needing to painstakingly re-create every setting.

CHAPTER 12

1. Because different IOS devices have different hardware capabilities (e.g., phone, GPS, camera), you should identify the device type when you are trying to access an IOS service to ensure that the device can support the request.

2. You should use the following URL protocols:

Phone number: tel:

Email message: mailto:

SMS: sms:

3. Yes. On iPhone, the maps.google.com link takes you to the native Maps app. On iPod touch, the same link takes you to web-based Google site in Safari.

CHAPTER 13

1. A bookmarklet uses the javascript: protocol followed by script code.

2. The data: protocol enables you to encode an entire page’s content — HTML, CSS, JavaScript, and images — inside a single URL.

3. If you are going to use images in a data URL then you need to encode them first.

CHAPTER 14

1. The user agent string of an iPad has the text iPad in its platform string portion.

2. Stroking refers to drawing a line on a path, whereas filling is the painting of an area inside a path.

3. A path is composed of a series of subpaths, such as a straight line or an arc, that together form a shape.

4. You can draw an encoded image to eliminate the need for an external image file for canvas drawing.

CHAPTER 15

1. A manifest file is a text file used to list the files you want to store in an offline cache.

2. Yes, make sure your server assigns the MIME type text/cache-manifest to the manifest extension.

3. Although cookies are sent back to the server, saved key-value data is not unless you explicitly do so through JavaScript. You also have greater control over the data persistence and window access to that data using key-value storage.

CHAPTER 16

1. The more important cross-platform is to you, the less you are typically able to provide a native IOS-like experience. jQuery Mobile is cross-platform whereas iWebKit is focused on IOS-specific look and feel.

2. jQuery Mobile.

CHAPTER 17

1. Yes. Loading additional files take 60% to 90% of the total load time an HTML page.

2. The longer your identifiers are, the more space your files take. Don’t go to extremes, though, and make them so short that they become hard to work with.

3. getElementById() is more efficient than using dot notation.

CHAPTER 18

1. alert() debugging is the use of alert() dialog boxes to display the current state of your code. The problem is that it is not only inefficient, but it can also throw off the timing of your script, making it difficult or impossible to simulate real-world results.

2. You can enable the Develop menu in the Preferences dialog box of Safari.

3. Enable the Debug Console through Settings ⇒ Safari ⇒ Developer. Once enabled, the Debug Console is displayed below the URL bar when an error occurs.

CHAPTER 19

1. Xcode, which is available for free from the Mac App Store.

2. All of the above. The Development Provisioning Profile is installed onto the IOS device itself, but it requires each of the other components.

3. Sorry, Windows fans. For better or worse, Xcode only runs on Mac OS X.

CHAPTER 20

1. False. Add your existing code to the index.html that comes with PhoneGap.

2. If you want to access an external resource, you need to add it to the project’s External Hosts white list in PhoneGap.plist.

3. Icons: Icon.png (57 × 57), [email protected] (114 × 114)

Launch: Default.png (320 × 480), [email protected] (640 × 960)

CHAPTER 21

1. Yes, you need to create a new certificate and Provisioning Profile for distribution.

2. An archive.

3. No. The review process by Apple can take days or even weeks.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset