The marketplace for apps is ever expanding, increasing thepotential to make money. With this guide, you'll learn how to buildcross-platform applications for mobile devices that are supportedby the power of Cloud-based services such as Amazon Web Services.An introduction to Cloud-based applications explains how to useHTML5 to create cross-platform mobile apps and then use Cloudservices to enhance those apps. You'll learn how to build yourfirst app with HTML5 and set it up in the Cloud, while alsodiscovering how to use jQuery to your advantage.
- Highlights the skills and knowledge you need to createsuccessful apps for mobile devices with HTML5
- Takes you through the steps for building web applications forthe iPhone and Android
- Details how to enhance your app through faster launching, touchvs. click, storage capabilities, and a cache
- Looks at how best to use JSON, FourSquare, jQuery, AJAX, andmore
- Shares tips for creating hybrid apps that run natively
If you're interested in having your application be one of the200,000+ apps featured in the iPhone store or the 50,000+ in theAndroid store, then you need this book.
|Product dimensions:||7.40(w) x 9.16(h) x 1.02(d)|
About the Author
Richard Rodger is the CTO of FeedHenry Ltd, a company specializing in bringing the first tools to develop cloud based applications for mobile devices. He is currently a member of the W3C Web Applications Working Group, which defines the standard for mobile widget applications.
Read an Excerpt
Beginning Building Mobile Application Development in the Cloud
By Richard Rodger
John Wiley & SonsCopyright © 2012 John Wiley & Sons, Ltd
All right reserved.
Chapter OneIntroducing Cloud-Based Mobile Apps
WHAT YOU WILL LEARN IN THIS CHAPTER:
* Using your existing skills as a web developer to build mobile apps
* Understanding how HTML5 will be used as an app-development standard
* Using the WebKit browser engine for app development
* Creating a mobile web app that responds to touch
* Installing and using the nginx web server
The code examples in this book show you how to build complete apps. You are never left to put together the pieces yourself. The code is simple and includes error-handling logic, so you'll learn how to build production-ready apps and systems.
Over the course of this book, you will build three complete applications. You'll learn how to put together all the elements of the technology stack, and you'll learn about a wide range of technologies and services. This book will enable you to get to work but avoids unnecessary detail and theory.
This book is an accelerator for your skills. You can use it to efficiently make the leap into mobile and cloud development. Rather than attempting to be a reference for all the details, which you can find on the web anyway, it is a stepping stone for your skills.
HOW TO BUILD MOBILE APPS IN THE CLOUD
This book describes how to build apps that run on the new generation of smart mobile devices. It also shows how to build out the business logic behind these apps, and how to run that business logic in a cloud hosting environment, such as that provided by Amazon.
This book focuses on the two leading platforms: iPhone and Android. These two, between them, cover the vast majority of smartphones and provide access to the largest market.
NOTE In this book, the term iPhone should be taken as shorthand for any iOS-based device, including iPad and the iPod Touch devices. Similarly, the term Android refers to any device running Android version 2.1 or higher, including any of the Android tablets that are competing with the iPad.
It's important to understand the types of apps that can run on mobile devices:
* Mobile web apps — These apps are really just websites, designed to function in an app-like way. They run in a web browser on a device.
* Purely native apps — These apps are written in a device-specific language, using a device-specific programming interface: Objective-C for iPhone apps or Java for Android apps. Native apps can access all the capabilities of the device and can take many forms, from simple utility apps to advanced 3-D games.
* Hybrid native apps — For these apps, you use HTML to build the user interface but wrap the HTML in a native container. Such apps can access some of the native capabilities of the device but can still be developed using HTML.
In this book you will learn how to build mobile web apps and hybrid apps.
Using Your Existing Skill Set
As a web developer, you already possess all the skills you need to be a mobile app developer as well. If you can build websites, you can build mobile apps. If you are a web developer wanting to build mobile apps, you do not need to learn new languages such as Objective-C or Java. You do not even need to learn new languages to build the code for servers that support your app.
Determining What Tools You Need
You'll need some development tools in order to fully explore the examples in this book. You will certainly find a physical iPhone or Android device very useful for testing and development. You need to run mobile apps on an actual device to really understand how they will behave once users get hold of them.
To a certain extent, you can develop the apps and code examples in this book on any of the three major operating systems: Mac, Windows, or Linux. However, you will find that a Mac is the best choice, simply because the iPhone development tools from Apple can only run on a Mac. Your Mac can also run the server code quite easily. One thing you should do is upgrade to the latest version of the Mac OS X operating system, as this will support the most up-to-date versions of the iPhone development tools.
Windows and Linux are also acceptable, although you will have to do a little more configuration and setup work. In particular, on Windows, you will need to install the Cygwin UNIX environment so that you can run Node.js. Cygwin is available from www.cygwin.com. As discussed in Chapter, 11, you will also have to rely on third-party services to build hybrid native iPhone apps.
You can build mobile web apps and the necessary server code using your existing development tools. All you need is a good code editor, and I'm sure you've already chosen a favorite for coding websites. You'll also be using the command line quite a bit, especially for the server code. But don't worry if you're not comfortable with the command line; this book gives you exactly the commands you need to run.
Later in this book, you'll need to download and install the software development kits (SDKs) for iPhone and Android development. These SDKs are provided as part of the Xcode (for iPhone) and Eclipse (for Android) development environments. Xcode runs only on a Mac, but you can run Eclipse on all three operating systems.
The final development tool you'll use is the Safari web browser. You can download this directly from the Apple website: www.apple.com/safari. You will use Safari as a test and deployment tool because Safari is built with the open source WebKit browser engine. This browser engine is used on both iPhone and Android, and it is the web browser environment for which you need to develop. In your coding work cycle, you will use the desktop Safari browser as your test system.
The Skills You'll Learn
As you work through this book, you'll learn and enhance a wide range of skills. These skills will cover the entire mobile app technology stack, from the device, to the server, to the database. These will be practical skills, and theory will be kept to a minimum. All the code examples in this book create complete, fully working apps. You'll be able to use them as foundations for your own work.
You'll make good use of the new features in HTML5 when you build mobile web apps and HTML5-based native apps. The Safari browser and the WebKit engine have good support for many of the features of HTML5. You'll be able to use local on-device storage, app caching, geolocation, and even audio and video support.
You'll also learn about the special metatags and design considerations needed for mobile web app development. These allow you to deal with different screen sizes and device capabilities. They also allow you to define home screen icons and loading screens for your app.
The app on a device is only part of the story. The aim of this book is to teach you how to create mobile apps that provide complete services. This means you'll need to write server code that handles some of your business logic, such as user account management, user data storage, and integration with third-party cloud services. You'll also learn how to provide social media logins using Facebook and Twitter.
You'll need a place to put your server-side code, so you'll learn how to host your code in the cloud, using Amazon Web Services (AWS). AWS is a full cloud-hosting system provided by Amazon that lets you create your servers and store images and files; it provides a nearly infinite database. You'll learn how to set up and configure an Amazon server and how to access the Amazon services over the web.
Finally, you'll learn how to work with next-generation databases that go beyond traditional tables, columns, and rows. You'll learn how to work with these schemaless database systems and how to synchronize them with the data on your mobile device.
TWO BIG IDEAS ABOUT THE APP INDUSTRY
This book is based on two predictions about where the app industry is going:
* Cloud computing will be the primary way to build the service infrastructure for apps — Most app developers accept this idea.
* Using HTML5 is a great way to build apps and will only become better — This view is still quite controversial.
The following sections take a closer look at these predictions and how they affect you, as a web developer and as a mobile app developer.
Web Apps and the Future
There are two types of web apps: mobile web apps and hybrid native apps. A mobile web app is delivered as a website and runs in a web browser on a mobile device. You can bookmark web apps on the home screen of the device, and you can give them icons and loading screens (as you'll see in Chapter 4). The user experience with mobile web apps is essentially different from that of native apps, but you can remove many of the differences.
This book will show you how to create both types of apps. You should carefully consider which approach is the best choice. The huge advantage of mobile web apps is that they are ultimately just websites, which means they do not have to be submitted to any app stores for approval. You can update them as frequently as you like, and they can be accessed from almost all smartphones (although functionality may be limited outside the iPhone and Android platforms).
However, hybrid native apps have the advantage of being proper apps that are listed in the app stores. They can use a device to its full potential, and you can extended these apps with native code, if necessary. You might be surprised to learn that a great many "purely" native apps actually make extensive use of HTML5 WebView controls. This is the main way to display rich text interfaces, even for purely native apps.
The following are the main reasons to develop an app using HTML5, whether as a mobile web app or within a hybrid native wrapper:
* Cross-platform — Your app is automatically cross-platform, and you have to develop it only once. The minor debugging required to handle device browser differences is inconsequential compared to the huge effort required to port an entire app from one platform language to another.
* Standards compliant — Long after the current set of mobile platforms have become historical entries in Wikipedia, your HTML5 app will still be running. HTML, as a technology choice, is a completely safe bet. It is quickly becoming the primary means of building user interfaces on any device, including tablet computers.
* Low-friction deployment — You can launch and update mobile web apps immediately, without waiting for a third-party approval process. You have complete control over content, user base, and commercial activities. No vendor is powerful enough to control the web.
* Easy to learn — You already have a good knowledge of web languages, so you can start building apps right away just by learning to deal with the particularities of mobile web app development. You do not need to invest any time in learning a new language such as Objective-C, which has limited use outside its own ecosystem.
The Cloud as the Future
Cloud computing means many things. For mobile app developers, it provides the ability to build apps that millions of people can use. Cloud computing makes it easier to handle large and growing numbers of users.
This book shows you how to build your own cloud-based system from the ground up, using the Amazon cloud. You can use the same basic approach with other cloud vendors, such as Rackspace or Joyent. Chapter 11 covers the use of higher-level services that completely remove the need for any server configuration and just run your code for you.
Excerpted from Beginning Building Mobile Application Development in the Cloud by Richard Rodger Copyright © 2012 by John Wiley & Sons, Ltd. Excerpted by permission of John Wiley & Sons. All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.
Table of ContentsINTRODUCTION xxi
CHAPTER 1: INTRODUCING CLOUD-BASED MOBILE APPS 1
How to Build Mobile Apps in the Cloud 2
Using Your Existing Skill Set 2
Determining What Tools You Need 3
The Skills You’ll Learn 4
Two Big Ideas About the App Industry 4
Web Apps and the Future 5
The Cloud as the Future 6
Getting Started 7
The WebKit Browser Engine 20
A Colorful Little App 21
Introducing the nginx Web Server 25
CHAPTER 2: MOBILIZING YOUR APP 31
Building a Touch-Sensitive Drawing App 32
How to Draw on the Screen 32
Drawing in Response to Touch Events 39
Applying the DRY Principle to Your Code 46
Using the Amazon Cloud 52
How Geography Aff ects Amazon AWS 54
Using the Elastic Compute Cloud 54
Deploying Your Mobile Web App 61
Deploying Your Mobile App to the Instance 65
CHAPTER 3: BUILDING MOBILE WEB APPS 71
What You Can Do with Mobile Web Apps 71
Locating Your User 72
Responding to Device Orientation 74
More Features for Later 76
Installing Mobile Web Apps on iPhone Devices 76
Installing Mobile Web Apps on Android Devices 77
Introducing jQuery and jQuery Mobile 78
The jQuery Library 78
The jQuery Mobile Library 83
Building a To-Do List App 91
CHAPTER 4: ENHANCING YOUR APP 111
Using App Caching 112
Handling Touch Events 115
Touch Events 116
Gesture Events 118
Embedding an Interactive Map 127
The Google Maps API 127
Providing an Application Icon and a Startup Screen 131
CHAPTER 5 : BUILDING APPS IN THE CLOUD 135
Introducing Node 136
Installing Node 138
Using the Node Package Manager 141
Introducing the MongoDB Database 144
Cloud Analytics for Your To-Do List App 150
Doing the Math 150
Organizing Your System 152
Collecting the Usage Data 160
Submitting the Usage Data 164
Charting the Usage Data 167
CHAPTER 6: USE THE CLOUD! 177
The Classic Cloud Architecture 177
The REST Approach 178
Cloud Databases 179
Introducing Amazon SimpleDB 180
The SimpleDB Approach to Cloud Storage 180
The SimpleDB API 181
Putting the To-Do List App in the Cloud 182
Introducing the simpledb Library 182
Building a Command-Line Client 188
Working on Cloud Time 196
Running a Cloud Server 198
Synchronizing with the Cloud 203
CHAPTER 7: ENHANCING THE USER EXPERIENCE 211
Creating a Classic Tab Bar Interface 211
Implementing the jQuery Mobile Solution 212
Using the iScroll Solution 216
Enabling Mobile Audio and Video 222
Playing Audio in Your App 222
Playing Video in Your App 226
Launching Apps from Your App 230
Launching a Web Browser from Your App 230
Launching a Phone from Your App 230
Launching SMS from Your App 230
Launching Mail from Your App 231
Launching Maps from Your App 231
Launching YouTube from Your App 231
CHAPTER 8: WORKING WITH THE CLOUD 235
Storing Content in Amazon S3 236
The Architecture of Amazon S3 236
Using Amazon S3 238
Signing In with the Cloud 247
Building Large-Scale Apps 255
Getting the Big Picture Right 256
Using the Cache! 258
CHAPTER 9: CREATING HYBRID APPS THAT RUN NATIVELY 273
Introducing Hybrid Apps 274
The PhoneGap Project 274
Building Hybrid Apps 275
Building an iPhone App 275
Understanding Code-Signing 276
Building an Android App 283
Using Device Features 288
Lifestream, a Photo-Blogging App 294
Uploading Pictures 295
Storing Pictures on Amazon S3 306
CHAPTER 10: BUILDING A PHOTO-BLOGGING APP 315
The Architecture of Lifestream 316
Building the Server 317
Laying the Foundation 317
Enabling User Following 333
Uploading and Posting Pictures 336
Completing the Lifestream App 345
Supporting User Accounts 346
Integrating Social Network Identity 357
CHAPTER 11: WORKING WITH CLOUD DEVELOPMENT SERVICES371
Getting to Know the Mobile App Development Platforms 372
Using the FeedHenry Platform 373
FeedHenry Technology 374
The FeedHenry Development Environment 375
Deciding to Use FeedHenry 376
Using the Appcelerator Platform 377
Appcelerator Technology 378
The Appcelerator Development Environment 379
Deciding to Use Appcelerator 380
Using the appMobi Platform 381
appMobi Technology 382
The appMobi Development Environment 383
Deciding to Use appMobi 384
CHAPTER 12: GOING SOCIAL! 387
Using the Twitter API 388
Working with the Twitter API Usage Limits 390
Using the Entities that the Twitter API Exposes 390
The Parts You Need 391
An App for Direct Messages 395
The Design Process 395
Getting the Hygiene Factors Right 399
The Code Structure 404
OAuth Without a Server 413
Calling the Twitter API 421
Event Consumers and Producers 425
CHAPTER 13: APP STORES 435
What You Need to Publish Your App 436
Splash Screen 438
Screenshots and Orientations 439
App Metadata 440
Working with the App Stores 440
Building Your App for Release 441
CHAPTER 14: SELLING YOUR APP 455
Determining a Marketing Strategy 456
Building Apps for Others 457
Using Apps to Promote Your Business 458
Selling Your Own Apps 460
Choosing Tactics for Promoting Your App 462
Standard Tactics 463
Expensive Tactics 465
Guerrilla Tactics 466
APPENDIX: EXERCISE SOLUTIONS 471