INTRODUCTION

The iPhone SDK was officially announced by Apple on March 6, 2008, at an Apple Town Hall meeting. In the early days of the SDK, iPhone development was shrouded in secrecy because Apple has imposed a Non-Disclosure Agreement (NDA) on developers who downloaded the SDK. No one was allowed to publicly discuss the SDK and the various APIs shipped with it. Apple had presumably done this to ensure the stability of the SDK. This move caused an uproar from developers because it prevented them from posting questions on public forums and getting help quickly. Nor could books be written about it or training courses developed. The adoption of Objective-C as the programming language for the iPhone SDK did not help. In fact, that language has a steep learning curve for developers, who for the most part are coming from more mainstream languages such as Java, C++, C#, and VB.NET.

With pressure from the public, Apple finally lifted the NDA in late 2008. This was welcome news to developers, albeit a little late. Overnight, discussion forums appeared and Web sites dedicated to iPhone development mushroomed.

Although Web sites and discussion forums talking about iPhone development are numerous, one obstacle remains — the learning curve for getting started is simply too great. Many developers are struggling to get started with Xcode and Interface Builder. At the same time, they have to grapple with the arcane syntax of Objective-C and to constantly remember which objects to free up and which ones not to.

This book was written to bridge the gap.

When I first started learning about iPhone development, I went through the same journey that most iPhone developers go through: Write a Hello World application, mess with Interface Builder, try to understand what the code is doing, and repeat that process. I was also overwhelmed by the concept of a View Controller and wondered why it is needed if I simply want to display a view. My background in developing for Windows Mobile and Android did not help much, and I had to start working with this concept from scratch.

This book is written to make the life of a beginning iPhone developer as easy as possible. It covers the various topics in such a manner that you will progressively learn without being overwhelmed by the details. I adopt the philosophy that the best way to learn is by doing, hence the numerous Try It Out sections in all the chapters, which first show you how to build something and then explain how things work.

Although iPhone programming is a huge topic, my aim for this book is to get you started with the fundamentals, understand the underlying architecture of the SDK, and appreciate why things are done certain ways. It is beyond the scope of this book to cover everything under the sun related to iPhone programming, but I am confident that after reading this book (and doing the exercises), you will be well equipped to tackle your next iPhone programming challenge.

WHO THIS BOOK IS FOR

This book is for the beginning iPhone developer who wants to start developing iPhone applications using the Apple iPhone SDK. To truly benefit from this book, you should have some background in programming and at least be familiar with object-oriented programming concepts. If you are totally new to the Objective-C language, you might want to jump straight to Appendix D, which provides an overview of the language. Alternatively, you can use Appendix D as a quick reference while you tackle the various chapters, checking out the syntax as you try the exercises. Depending on your learning pattern, one of those approaches may work best for you.

WHAT THIS BOOK COVERS

This book covers the fundamentals of iPhone programming using the iPhone SDK. It is divided into 17 chapters and five appendices.

Chapter 1: Getting Started with iPhone Programming covers the various tools found in the iPhone SDK and explains their uses in iPhone development.

Chapter 2: Write Your First Hello World! Application gets you started with Xcode and Interface Builder to build a Hello World application. The focus is on getting your hands dirty, and more details on the various parts and components are covered in subsequent chapters.

Chapter 3: Outlets, Actions, and View Controllers covers the fundamental concepts of iPhone programming: outlets and actions. You learn how outlets and actions allow your code to interact with the visual elements in Interface Builder and why they are an integral part of every iPhone application.

Chapter 4: Exploring the Views describes the use of the various views that make up the user interface (UI) of your iPhone applications. You learn the techniques to manipulate the UI of your application, as well as how views are stored internally.

Chapter 5: Keyboard Inputs shows you how to deal with the virtual keyboard in your iPhone. You see how to hide the keyboard on demand and how to ensure that your views are not blocked by the keyboard when it is displayed.

Chapter 6: Screen Rotations demonstrates how you can reorient your application's UI when the device is rotated. You learn about the various events that are fired when the device is rotated. You also learn how to force your application to display in a certain display orientation.

Chapter 7: View Controllers shows how you can create an application with multiple views. You learn how to build an iPhone application using the Window-based Application template.

Chapter 8: Tab Bar and Navigation Applications shows you how to build Tab Bar applications and Navigation applications using the templates provided by the SDK. Using these two application templates, you can create sophisticated multiview applications.

Chapter 9: Utility Applications shows you how to build yet another type of application in the iPhone — utility applications.

Chapter 10: Using the Table View explores one of the most powerful views in the iPhone SDK — the Table view. The Table view is commonly used to display rows of data. In this chapter, you also learn how to implement search capabilities in your Table view.

Chapter 11: Application Preferences discusses the use of application settings to persist application preferences. Using application settings, you can access preferences related to your application through the Settings application available on the iPhone and iPod Touch.

Chapter 12: Database Storage Using SQLLite3 covers the use of the embedded SQLite3 database library to store your data.

Chapter 13: File Handling shows how you can persist your application data by saving the data to files in your application's sandbox directory. You also learn how to access the various folders available in your application sandbox.

Chapter 14: Programming Multi-touch Applications shows how you can implement multi-touch capability in your iPhone application. You learn how to implement gestures such as the famous "pinching" gesture.

Chapter 15: Simple Animations provides an overview of the various techniques you can use to implement simple animations on the iPhone. You also learn about the various affine transformations supported by the iPhone SDK.

Chapter 16: Accessing Built-in Applications describes the various ways you can access the iPhone's built-in applications, such as the Photo Library, Contacts, and others. You also learn how you can invoke built-in applications such as Mail and Safari from within your applications.

Chapter 17: Accessing the Hardware shows you how you can access the hardware of your iPhone, such as the accelerometer, as well as how to obtain your geographical information through Core Location.

Appendix A: Answers to Exercises contains the solutions to the end of chapter exercises found in every chapter except Chapter 1.

Appendix B: Getting around in Xcode provides a quick run-through of the many features in Xcode.

Appendix C: Getting around in Interface Builder provides an overview of the many features of Interface Builder.

Appendix D: Crash Course in Objective-C provides a crash course in Objective-C. Readers who are new to this language should read this chapter before getting started.

Appendix E: Testing on an Actual iPhone or iPod Touch shows how you can test your application on a real device.

HOW THIS BOOK IS STRUCTURED

This book breaks down the task of learning iPhone programming into several smaller chunks, allowing you to digest each topic before delving into another more advanced topic. In addition, there are a few chapters that cover topics already discussed in the previous chapter. This is because there is usually more than one way of doing things in Xcode and Interface Builder, and hence this approach allows you to learn the different techniques in developing iPhone applications.

If you are a total beginner to iPhone programming, it would be motivational for you to start with Chapters 1 and 2. Once you have gotten things moving, head on to the Appendices to read more about the tools and language you are using. Once you are ready, you can now continue with Chapter 3 and gradually move into more advanced topics.

A feature of this book is that all the code samples in each chapter are independent of those discussed in previous chapters. That way, you have the flexibility to dive into the topics that interest you and start working on the Try It Out labs.

WHAT YOU NEED TO USE THIS BOOK

Most of the examples in this book run on the iPhone Simulator (which comes as part of the iPhone SDK). For exercises that access the hardware (such as the camera and accelerometer), you need a real iPhone or iPod Touch. Appendix E shows how you can test your application on a real device. For applications that access the phone function, you need an actual iPhone (the iPod Touch has no built-in phone).

In general, to get the most out of this book, having a real iPhone or iPod Touch is not necessary (although it is definitely required for testing if you plan to deploy your application on the AppStore).

CONVENTIONS

To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.

SOURCE CODE

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All the source code used in this book is available for download at www.wrox.com. When at the site, simply locate the book's title (use the Search box or one of the title lists) and click the Download Code link on the book's detail page to obtain all the source code for the book. Code that is included on the Web site is highlighted by the following icon.

SOURCE CODE
Listings include the filename in the title. If it is just a code snippet, you'll find the filename in a code note such as this.

Note

Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978-0-470-50097-2.

After you download the code, just decompress it with your favorite compression tool. Alternatively, go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

ERRATA

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, such as a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata, you may save another reader hours of frustration and at the same time help us provide even higher-quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page, you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list including links to each book's errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don't spot "your" error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.

P2P.WROX.COM

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com, you will find a number of different forums that will help you not only as you read this book but also as you develop your own applications. To join the forums, just follow these steps:

  1. Go to p2p.wrox.com and click the Register link.

  2. Read the terms of use and click Agree.

  3. Complete the required information to join as well as any optional information you want to provide and click Submit.

  4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

Note

You can read messages in the forums without joining P2P, but to post your own messages, you must join.

After you join, you can post new messages and respond to messages that other users post. You can read messages at any time on the Web. If you want to have new messages from a particular forum e-mailed to you, click the Subscribe to This Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as for many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

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

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