Preface
It's fair to say that while Steve Jobs didn't necessarily start a smartphone revolution with the iPhone and iPad he certainly championed it and in doing so created beautifully designed devices that rightfully became both massively popular and highly desired.
Not long after the introduction of these seductive devices came another masterstroke, the App Store. Apple generated massive developer interest by promoting the dream of becoming a rock-star developer by creating apps for this new platform. It was a massive success; a new breed of indie developers flocked to the platform pushing new apps into the App Store hoping their app would be the one to make it big.
The App Store opened in June 2008 with only 500 apps. By October 2011 there were over half a million apps, and it continues to grow with over 500 new apps published everyday. There will soon be 1 million apps available which has resulted in an ecosystem that has paid out over six billion dollars in royalties. Thanks to a lucrative payment strategy whereby Apple gets 30 percent of revenue from every sale, they have become one of the biggest companies in history.
Success of that size doesn't go unnoticed or unchallenged. The monopoly didn't last long and soon after Google came along with Android and its own Android marketplace. While initial take-up was slower than Apple, it has gained ground and by late 2012 both stores had equal number of apps available.
Now the app market has two major players. You can create an app for iOS or Android, but unfortunately there are no common compilers for the two systems, so if you want to write a native app for iOS, you have to use objective-C and Java for Android.
Jeff Haynie and Nolan Wright (the founders of Appcelerator) were ahead of all of this; they already had a way of creating native apps for iOS using JavaScript, and it just so happened that the methodology they used in their Titanium tool would also work for Android. Titanium was launched in 2009 and since then it has attracted over 400,000 registered developers.
Titanium allows you to create native apps that will run on both iOS and Android. A Titanium app can be run on both platforms without changing a single line of code. Over 50,000 apps have been released using the technology; this book will help you to add your app to that list.
The book will guide you through the process of creating a cross-platform app, an app that can be released to both Android and iOS app stores.
The book has been written in a relaxed and friendly manner with carefully selected examples that highlight the core concepts of the chapter. All examples, unless specifically stated, are written so that they may be run on both platforms.
The chapters have been ordered to reflect the order in which I believe the tool should be learned. The initial chapters will provide guidance on how to install and configure the tool before moving on to how to create apps using Titanium. The book then looks in detail at how to design and structure apps. This is the content that will be invaluable later when your apps become larger and more complex. Being able to easily modify and extend your apps because they have been designed with a well-defined structure will be a significant advantage.
The next few chapters then focus on some of the core components of apps with chapters on the cloud, phone gadgets, and data. After this we move on to an important area, interface design, and how to create apps that will run and look good on phones and tablets from both iOS and Android.
Next, the book has a couple of chapters that look into a few optional extras such as social media integration and push notifications, before moving on to the final phase of testing and deploying your app to the app store.
The final two chapters focus on areas that are often considered by developers after an app has gone live, namely analytics and making money from your app.
What this book covers
Chapter 1, How to Get Up and Running with Titanium, guides you through the process of installing Titanium and setting up the Android and iOS SDKs. It then shows you how to create your first, simple cross-platform app and explains the core components of all Titanium apps.
Chapter 2, How to Make an Interface, introduces the tools that are available for making an interface and shows how you can design apps that make use of platform specific features. The next two chapters provide guidance on how to design and structure a Titanium application. Furthermore, they explain how a Titanium app is connected and how the use of best practices will result in more manageable code.
Chapter 3, How to Design Titanium Apps, delves into the detail of how to structure a Titanium app, and how the use of best design practices results in more manageable, stable, and reusable code. It also explains the Model View Controller (MVC) design methodology and touches on Alloy, the latest in design models for Titanium.
Chapter 4, Gluing Your App Together With Events, Variables, and Callbacks, explains how different parts of your app communicate with one another, for example, how a slider indicates its value to a label. It gives a thorough examination of events and also explains some of the problems of defining global variables and how to avoid creating them.
Chapter 5, It's All About Data, describes how to communicate with external sources using HTTP requests. It also covers how to store data locally in files, databases, or properties. Finally, it provides a worked example of how to show foreign exchange prices using Yahoo Query Language (YQL).
Chapter 6, Cloud-enabling Your Apps, looks at how to integrate cloud services into your app and how they can be used to store and retrieve data. It shows examples of Appcelerator Cloud Services and shows the principles of integrating any REST based service.
Chapter 7, Putting the Phone Gadgets to Good Use, describes how to integrate phone gadgets into your app. It provides examples of the camera, compass, geolocation, maps, directions, and accelerometer. It also shows how these gadgets can be combined together to produce an Augmented Reality (AR) experience.
Chapter 8, Creating Beautiful Interfaces, details how to build interfaces that work on both platforms and how the same interface can be altered to produce a different layout for phones and tablets. It also looks into how to break down a complex screen into smaller views and how to handle and control orientation.
Chapter 9, Spread the Word with Social Media, shows how your can integrate Facebook and Twitter into your application. It also shows an alternative way of sharing information on Android using intents.
Chapter 10, Sending Notifications, shows how to add push notification support into your app. It details the full workflow for push notifications from registering with a provider to acting on the notification from within your app.
Chapter 11, Testing and Deploying, examines how to test your app on devices and includes detail on creating certificates and provisioning profiles. It also guides you through the process of successfully deploying your app to iOS and Android stores.
Chapter 12, Analytics, provides examples of how to integrate three analytic providers, namely, Appcelerator Analytics, Flurry, and Google Analytics into your app, and shows the benefits of gathering analytic information.
Chapter 13, Making Money from Your App, provides examples of how to make money from your app. It focuses on integrating adverts from suppliers such as Google AdMob and how you can use in-app purchases to add premium paid functionality into your app.
Appendix A, Git Integration, discusses the integration of Titanium Studio with the cloud-based GitHub source control system.
Appendix B, Glossary, contains the list of terminologies used in the book.
What you need for this book
You can install Titanium onto a PC or Mac running Windows, OS X, or Ubuntu. Apple only supplies iOS development tools for the OS X environment so if you are planning to deploy your app onto iOS, you will need access to OS X. If you have a Mac, you can develop apps for both iOS and Android. Full details of compatibility can be found at http://docs.appcelerator.com/titanium/3.0/#!/guide/Titanium_Compatibility_Matrix.
You also need to sign up for an iOS or Google developer account depending on the platforms you are developing for.
Who this book is for
The primary purpose of this book is to provide developers with a guide to creating apps that can be released for both iOS and Android. The book will be particularly well suited to developers with experience of creating web-based content.
It is assumed that the reader already has a working knowledge of JavaScript as well as some of the key standards, such as XML.
Conventions
In this book, you will find several headings appearing frequently.
To give clear instructions of how to complete a procedure or task, we use:
Time for action – heading
Action 1
Action 2
Action 3
Instructions often need some extra explanation so that they make sense, so they are followed with:
What just happened?
This heading explains the working of tasks or instructions that you have just completed.
You will also find some other learning aids in the book, including:
Pop quiz – heading
These are short multiple-choice questions intended to help you test your own understanding.
Have a go hero – heading
These practical challenges will give you ideas for experimenting with what you have learned.
You will also find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "KS_nav_ui.png
and KS_nav_views.png
are the two icons that appear at the bottom of the screen on the tabs."
A block of code is set as follows:
# * Fine Tuning # key_buffer = 16M key_buffer_size = 32M max_allowed_packet = 16M thread_stack = 512K thread_cache_size = 8 max_connections = 300
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
# * Fine Tuning
#
key_buffer = 16M
key_buffer_size = 32M
max_allowed_packet = 16M
thread_stack = 512K
thread_cache_size = 8
max_connections = 300
Any command-line input or output is written as follows:
cd /ProgramData/Propeople rm -r Drush git clone --branch master http://git.drupal.org/project/drush.git
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "On the Select Destination Location screen, click on Next to accept the default destination."
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <feedback@packtpub.com>
, and mention the book title through the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <copyright@packtpub.com>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions
You can contact us at <questions@packtpub.com>
if you are having a problem with any aspect of the book, and we will do our best to address it.