01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The iPhone SDK: Safari<br />

319<br />

It’s important to note that web applications currently—and probably always will—<br />

have<br />

less access to hardware features and operating system services than do <strong>Objective</strong>-C<br />

applications. Examples of features currently accessible only from <strong>Objective</strong>-C include<br />

the user’s address book, camera photo library, and iPod music. Constant improvements<br />

are being made in this regard; for example, iPhone OS 3.0 introduced the capability<br />

for web applications to access GPS location information, and iOS 4.2 added<br />

access to accelerometer data. But the web application platform will always present the<br />

developer with a subset of the features accessible to native developers, if only because<br />

Apple engineers must expend additional effort to produce JavaScript-accessible wrappers<br />

for any feature they want to expose to web applications, and additional security<br />

and privacy concerns arise with features that can be accessed by any website.<br />

C.3.3<br />

PhoneGap and other extensible cross-platform solutions<br />

Developers need not abandon HTML, CSS, and JavaScript as their development platforms<br />

if they find the built-in services of the Safari web browser and web-based applications<br />

inadequate for their application needs.<br />

A number of solutions exist to enable applications written in web-based technologies<br />

to run outside of the traditional Safari browser–based environment and, in the<br />

process, to gain greater access to system hardware. One example of this approach is a<br />

development tool called PhoneGap (www.phonegap.com). PhoneGap is an open<br />

source product that enables you to build applications in HTML and JavaScript. Unlike<br />

a web application running in Safari, however, your JavaScript source code also has<br />

access to the PhoneGap SDK APIs, which provide access to additional features of the<br />

mobile platform, such as Geolocation, Vibration, Accelerometer, Contacts, and Sound.<br />

This accessibility is achievable because a PhoneGap application is a native iOS<br />

application, built using <strong>Objective</strong>-C and Xcode, just as we’ve discussed throughout<br />

this book. Most of the application is a predeveloped <strong>Objective</strong>-C component (which<br />

for the most part is hidden and automatically inserted by the project template) that<br />

sets up a UIWebView control to display the HTML and JavaScript content embedded in<br />

you Xcode project. The magic occurs because the <strong>Objective</strong>-C component exposes<br />

additional services that your JavaScript can hook into. All your web application must<br />

do is include a element that imports the main PhoneGap JavaScript file.<br />

Appearing as a standard <strong>Objective</strong>-C-based iOS application, at least from the outside,<br />

means PhoneGap applications can be distributed via the iTunes App Store,<br />

which provides an easy monetization and consumer discovery/marketing approach.<br />

Because the core of your PhoneGap application is written in HTML, CSS, and<br />

JavaScript, it’s fairly portable across most mobile platforms, so it shouldn’t surprise<br />

you that the native part of PhoneGap is available for a number of platforms, including<br />

Android, Windows Mobile, iPhone, and Blackberry. By combining your platformagnostic<br />

JavaScript with a device-specific shell that deals with setting up a web<br />

browser control, then wrapping the device’s features into a consistent PhoneGap<br />

JavaScript-based API, you can have your cake and eat it too—developing iPhone

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!