Book Image

Appcelerator Titanium Smartphone App Development Cookbook

By : Boydlee Pollentine, Jason Kneen, Jason Kneen
Book Image

Appcelerator Titanium Smartphone App Development Cookbook

By: Boydlee Pollentine, Jason Kneen, Jason Kneen

Overview of this book

This book will take you through the process of building cross-platform, native UI applications for the mobile from scratch. You will learn how to develop apps, how to use GPS, cameras and photos and how to build socially connected apps. You will also learn how to package them for submission to the App Store and Google Play. This cookbook takes a pragmatic approach to creating applications in JavaScript from putting together basic UIs, to handling events and implementation of third party services such as Twitter, Facebook and Push notifications. The book shows you how to integrate datasources and server APIs, and how to use local databases. The topics covered will guide you to use Appcelerator Studio tools for all the mobile features such as Geolocation, Accelerometer, animation and more. You’ll also learn about Alloy, the Appcelerator MVC framework for rapid app development, and how to transfer data between applications using URLSchemes, enabling other developers to access and launch specific parts of your app. Finally, you will learn how to register developer accounts and publish your very own applications on the App Store and Google Play.
Table of Contents (21 chapters)
Appcelerator Titanium Smartphone App Development Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Before Titanium, building native mobile applications for multiple platforms meant learning Objective-C/Swift, Java, and C#. As a result, many application developers would specialize in supporting limited platforms, simply because they didn't have the time or skill set to rewrite application code in multiple languages.

Similarly, anyone looking to build an application on multiple platforms would have to employ a multi-skilled developer, or hire multiple developers or agencies to complete the task. This could be expensive, requiring application code to be written multiple times in different languages and environments, and could easily lead to releasing an application on only one platform initially, typically iOS.

The introduction of Titanium changed all this, allowing developers to use the JavaScript language to write cross-platform, native applications for multiple platforms from a single code base.

Titanium's unique approach means that a single developer can write native applications for iOS, Android, and now Windows Phone, targeting the unique features of each platform.

In this book, we'll cover all the aspects of building your mobile applications in Titanium, from visual layout to maps and GPS, all the way through data and social media integration and accessing your device's input hardware, including the camera and microphone. We'll also cover Alloy, the new framework from Appcelerator that allows rapid application development using the MVC (Model, View, Controller) methodology, and intercommunication between apps using URL schemes.

We'll go through how to extend your applications using custom modules, and how to package them for distribution and sale in both the iTunes App Store and the Android Play Store.

What this book covers

Chapter 1, Building Apps Using Native UI Components, begins our journey into Titanium Mobile by explaining the basics of layout and creating controls, before moving on to tabbed interfaces, web views, and how to add and open multiple windows.

Chapter 2, Working with Local and Remote Data Sources, helps you build yourself a mini-app that reads data from the Web using HTTP requests. We also see how to parse and iterate data in both XML and JSON formats. Then we see how to store and retrieve data locally using a SQLite database and some basic SQL queries.

Chapter 3, Integrating Google Maps and GPS, is where we add a MapView to our application and interact with it using annotations, geocoding, and events that track the user's location. We also go through the basics of adding routes and using the device's inbuilt compass to track our heading.

Chapter 4, Enhancing Your Apps with Audio, Video, and Camera, shows you how to interact with your device's media features using Titanium, including the camera, photo gallery, and audio recorder.

Chapter 5, Connecting Your Apps to Social Media and E-mail, teaches you to leverage Titanium and integrate it with Facebook, Twitter, and the e-mail capabilities of your mobile devices. Here, we also go through setting up a Facebook application and cover a brief introduction of the world of OAuth.

Chapter 6, Getting to Grips with Properties and Events, briefly runs through how properties work in Titanium and how you can get and set global variables in your app. In this chapter, you also learn how event listeners and handlers work and how to fire events, both from your controls and custom events from anywhere in your application.

Chapter 7, Creating Animations, Transformations and Implementing Drag and Drop, shows you how to create animations, and how to transform your objects using 2D and 3D matrices in Titanium. We also run through dragging and dropping controls and capturing screenshots using the inbuilt toImage functionality.

Chapter 8, Interacting with Native Phone Applications and APIs, is where you discover how to interact with native device APIs, such as the device's contacts and calendar. You also discover how to use local notifications and background services.

Chapter 9, Integrating Your Apps with External Services, dives deeper into OAuth and HTTP authentication, and also shows you how to connect to external APIs such as Yahoo! YQL and Foursquare. We also run through the setup and integration of push notifications into our Titanium apps.

Chapter 10, Extending Your Apps with Custom Modules, tells you how you can extend the native functionality in Titanium and add your own custom native modules using Objective-C and Xcode. Here, we run through a sample module from start to finish in Xcode to create short URLs using the Bit.ly service.

Chapter 11, Platform Differences, Device Information, and Quirks, shows you how to use Titanium to get information about the device, including important features such as making phone calls, checking the memory, and checking the remaining allocation of the battery. We also go through screen orientations and how to code differences between the iOS and Android platforms.

Chapter 12, Preparing Your App for Distribution and Getting It Published, demonstrates how to prepare and package your applications for distribution and sale on the iTunes App Store and Android Marketplace, along with a background of setting up and provisioning your apps correctly with provisioning profiles and development certificates.

Chapter 13, Implementing and Using URL Schemes, we will show how to use URL schemes to allow inter-app communication, from launching other apps to sending data between your own applications.

Chapter 14, Introduction to Alloy MVC, we will cover the Alloy MVC (Model, View Controller) framework, allowing you to build cross-platform applications faster than traditional Titanium mobile development.

What you need for this book

You will need a Mac running Xcode (the latest version, which is available at https://developer.apple.com/) and the Appcelerator Studio software (available at http://www.appcelerator.com/). You must use a Mac, as all instructions are based on it (Unix) because of the iPhone. Using a PC is not recommended, or supported anyway, for the Apple iPhone.

Who this book is for

This book is essential for any developer who is learning or using JavaScript and wants to write native UI applications for iOS and Android. No knowledge of Objective-C, Swift, or Java is required, and you'll be quickly developing native cross-platform apps in JavaScript.

Conventions

In this book, you will 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 are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

actionBar = win.activity.actionBar; 

if (actionBar) {
actionBar.backgroundImage = "/bg.png";
actionBar.title = "New Title"; 
}

Any command-line input or output is written as follows:

gittio install com.packtpub.bitlymodule-iphone-1.0.0.zip

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: "If everything is installed correctly, you should see a PayPal button appear on the screen."

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 , and mention the book title via 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 from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/7705OT.pdf.

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 could 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.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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 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

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.