Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 459 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
459
Dung lượng
18,24 MB
Nội dung
IPHONEAPP DEVELOPMENT
Kuh
In this book, you’ll:
Develop with Xcode, write Objective-C, and work with the latest iOS SDK
Create navigation hierarchies and table view controllers
Design, plan, and develop aniPhoneapp from the initial app idea to App Store submission
Storyboard and implement a custom-designed user interface
Work with Core Data to buildan offline caching solution
Implement asynchronous HTTP API calls to download and display images
Use the new iOS appearance API for custom design implementation and creating
beautiful apps
Increase your app’s chances for success in the App Store
Connect your app up to Facebook with Apple’s new social framework and take
advantage of in-app social network marketing in the process
Foundation iPhoneApp Development:
Build AniPhoneAppin5DayswithiOS6 SDK
Foundation iPhoneApp Development: BuildaniPhoneAppin5DayswithiOS6SDK
details tried and tested methods that will enable you to quickly build your first pro-
fessional, custom-designed app.
Author Nick Kuh, an experienced, Apple award-winning developer, helps you get up-
and-running with Objective-C and shows you how to effectively exploit your knowl-
edge of object-oriented programming to code great iOS apps.
You’ll start with a Photoshop PSD design and an idea. Then, throughout the remain-
der of the book, Nick guides you through each stage of building the app.
After reading and using this book, you’ll come away with coding concepts and a core
iOS development process that can be re-used and applied to your own iPhoneapp
projects. Foundation iPhoneApp Development teaches you how to think like a devel-
oper. It gives you the power to turn any idea into a beautiful iPhone app.
SHELVING CATEGORY
1. MOBILE COMPUTING
Available from Apress
FOUNDATION
US $29.99
Mac/PC compatible
www.apress.com
Your first iPhone apps development guide
for Web and Flash developers
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
iv
Contents at a Glance
About the Author xi
About the Technical Reviewer xii
About the Cover Image Artist xiii
Acknowledgments xiv
Introduction xv
Day 1: Objective C, Xcode and iOSSDK Foundation Work 1
Chapter 1: Designing and Planning Our App 3
Chapter 2: Provisioning Our App for Development 21
Chapter 3: Setting Up Our Xcode Project 41
Chapter 4: Objective-C and Xcode: Developing a Blackjack Game 63
Day 2: Storyboarding the User Interface 109
Chapter 5: iPhoneApp Navigation, Views, and View Controllers 111
Chapter 6: Views, Controls, Camera, Action! 143
Day 3: Working with Data 169
Chapter 7: Table Views, Arrays, and Dictionaries—Oh My! 171
Chapter 8: Data Persistence with Core Data 193
Chapter 9: iOS Skinning: Make Your Apps Lickable 235
Day 4: Importing Birthdays from the Address Book and Facebook 275
Chapter 10: Importing Birthdays from the Address Book 277
Chapter 11: Working with Facebook and the iOS6 Social Framework 327
Chapter 12: Settings and Local Notifications 367
Day 5: The Finishing Touches 393
Chapter 13: Before You Launch: Increasing Your Chances of App Store… 395
Chapter 14: Submitting Our App 417
Index 439
xv
Introduction
My programming roots originated with Flash in 1999 when I first started writing object-oriented Games and
Applications in ActionScript. More recently, in 2009, shortly after Apple launched the App Store and
opened up their exciting new mobile platform to third parties, I decided to jump ship and become an
iPhone Developer.
The transition from developing for the Flash Player to the iPhone was not the smoothest ride, but one key
factor that helped me more than anything is that the same foundation principals of object-oriented
programming for Flash are also at the heart of Objective-C and the iOS SDK.
If you are already working with another object-oriented language then you should be able to apply that
knowledge to Objective-C and soon be up-and-running building apps for the iPhone.
Who should buy this book
Are you a Flash or Java Developer? PHP or Ruby Programmer? You’re already proficient in at least one
other object-oriented programming language and want to extend you skillset to include the hugely popular
iOS platform. This book is for you.
Or perhaps you’re a beginner iPhone Developer. You’ve already worked through many of the code
examples that other books provide. You’re now looking to learn how to build a larger scale app and pooling
together knowledge you’ve gained from working through these example code snippets isn’t at all obvious.
If you’re completely new to programming then you may find this book quite challenging. However, I’ve
always found that getting stuck in, even at the deep-end, is often a great way to face new challenges. If
you’re a newbie but also a fast learner then welcome aboard! I’ll keep you in mind during our journey.
My book will help you to conquer the challenges of getting up-and-running with Objective-C. I will help you
to effectively exploit your knowledge of object-oriented programming to code great iOS Apps. Don’t worry if
your object-oriented code is a bit patchy though. Throughout this book I will regularly highlight how iOS
applies the Model View Controller (MVC) paradigm.
I’ll get your hands dirty with Xcode from the off. This is going to be a very hands-on book. After all, we’ve
only got 5days to buildan app!
You can even download the app we’ll be developing right now as it’s live in the App Store under the title
Birthday Reminder for Facebook.
What this book with teach you
Other books will provide you with chapter after chapter of code examples for the various frameworks in the
iOS SDK but when it comes to building your app you’ll then need to figure out how best to combine those
concepts together.
This book employs a very different method to learning. I will teach you how to build a professional, custom-
designed, object-oriented iPhoneAppin just 5 days.
Introduction
xvi
We’ll start with a Photoshop PSD design and anapp idea. Then, throughout the remainder of the book, I
will guide you through each stage of building this app. But it’s you who will build the app. You will learn
how to think like anapp developer, how to turn an idea into a beautiful iPhoneapp and a great number of
tips and tricks along the way.
You’ll learn a development process that I’ve devised over the last 3+ years that you will be able to apply to
your own apps after completing the course.
The App that you’ll be developing is quite simple on the surface, but the development principals it
introduces are equally suitable for the development of larger, more complex apps.
Over time I’ve discovered there are often many different ways to solve the programmatic challenges that
one faces on a daily basis when building iOS apps. Challenges like:
The best way to load remote images into a scrolling table view that won’t lock up the user
interface and keep the app optimized.
How to persistently store user data such as text and images and facilitate the user to edit and
change that data, or cancel their changes.
How to implement a custom app design without having to build custom iOS view components.
This book will address these kinds of challenges with solutions that I make use of in my own commercial
projects. Solutions that will save you days, months, even years of invested time!
The process I’ll exercise to teach you the skill of programming iOS Apps will be a step-by-step process.
We are going to buildanApp from conception to completion. You are going to build this app! Along the
way you’ll learn:
How to capitalize on making your beautiful app design resonate thanks to Apple’s high resolution
retina displays on all the new iPhone and iPod Touch devices
How to map out/mock-up all the views of your app very quickly using Storyboards in Xcode and
iOS 6
How to build view controllers with object-oriented inheritance – centralizing core, reusable
methods. Less code. Fewer bugs. Easier to make future changes.
How Core Data will solve all of your app’s data persistence needs. Although, this is quite an
advanced topic I’ll provide you withan easy-to-follow introduction to Core Data that will form the
foundation for more complex projects. Stay friends with Core Data. It’s worth it
How to deeply integrate Facebook’s Graph API using the very latest Social framework introduced
by Apple iniOS6.
How to take advantage of in-app social network marketing – get your users promoting your great
app to their friends!
There’s a lot to cover here!
Introduction
xvii
What this book won’t teach you
This is not a reference book for the iOS SDK. I won’t be providing examples of every iOS framework.
There are many other great books that do this already.
1
Day 1
Objective C, Xcode and iOSSDK
Foundation Work
3
Chapter 1
Designing and Planning Our App
Author: Throughout the course of this book, you will buildanapp from conception to completion!
You: Yes, Sensei!
Author: I expect you to build this app yourself. That’s the only way you’re going to learn!
You: Yes, Sensei!
OK, enough of The Karate Kid references (well, there may be a few more along the way ). The point I’m
making is that via a step-by-step, chapter-by-chapter process, I will be your tutor—but you will have to put
in the donkeywork. You are expected to write every line of code for this app. You are expected to create
every class and view in this app.
I will provide you with all the design assets for this project. I’ve even cut them up into the actual image
assets that you’ll embed into your own app.
If you want to really challenge yourself, don’t even look at the staged source code—throw it away! Just
work with the exported image asset files and write all the code yourself.
I will also provide the start and finish source code for each chapter of your app development journey. So if
you ever get stuck or want to jump ahead to a specific section of the app, go right ahead. How’s the
Sensei going to find out anyway?
Throughout this chapter, we’ll focus on the initial planning and design stage of building a new iPhone app:
how to get started once you have your app idea, a look at the competition for your app, and a number of
tips and tricks to help your app stand out from the hundreds of thousands of apps in Apple’s App Store.
Chapter 1
4
The app idea
We’ve all forgotten a birthday before, right?
The app you’re going to build is a birthday reminder app. Birthday Reminder will ensure that our users
never forget a birthday again! It’s a simple but useful idea and just the sort of thing that makes for a good
iPhone app idea.
With Birthday Reminder, all of your friends’ and family members’ birthdays are stored in one place. You’ll
get a notification reminder on the day of or in advance of every birthday. No more embarrassing late cards
and presents. Our app will solve this core problem for our users. It’s a single task that the app will do
seamlessly—making the user’s life a little easier.
A common misconception by some app developers is to think that adding more features to their app will
increase its popularity and App Store ranking. Instead, keep your app ideas simple—and deliver a
beautiful, intuitive user experience. Focus on doing one thing really well with your app rather than doing
ten things badly.
This app is going to stand out from the competition. Its icons and user interface are going to be so
beautiful, it’s going to make you want to lick your iPhone! The user experience is going to be instantly
intuitive to new users. The app will also be zippy and responsive to touch—just what iOS users have come
to expect from great iPhone and iPad apps!
Adding and editing birthdays
Users of our app will be able to add and edit an unlimited number of birthdays. We’ll include the option to
assign a photo to each birthday via the iPhone camera or Photo Library.
All birthdays will be stored offline in a local database on the iPhone. We’ll read and write to the database
via Apple’s Core Data framework (you’ll learn more about Core Data in Chapter 8).
Importing birthdays from the Address Book and Facebook
We’ll program an import mechanism into our app that facilitates our users to batch-import birthdays using
the latest iOS6 Facebook social integration and native Address Book frameworks. We won’t force our
users to import every one of his or her Facebook friends, however. We’ll allow them to pick and choose.
This is one of the great benefits of creating our own custom offline storage solution: we control the data.
Saving selected birthdays persistently in our app also means that we won’t lose this data and have to
resync our appwith the Address Book or Facebook, even if the OS shuts it down—which of course it never
will because we’re building an optimized app here.
Note taking
We’ll include a note-taking option in our app—the perfect way for our user to keep track of gift ideas. Notes
will also be saved and stored in our offline Core Data store.
Designing and Planning Our App
5
Reminder notifications
Our app will take advantage of local notifications in the iOS SDK. In our app code, we’ll schedule these
notification alerts, which will fire on the user’s iPhonein time for each birthday reminder—even when our
app isn’t running. We’ll also play a little Happy Birthday jingle with our birthday reminders.
Facebook social integration and in-app marketing
We won’t stop at just importing Facebook birthdays into our App. We’ll learn how to deeply integrate with
Facebook’s Graph API and Apple’s iOS6 social framework to enable users to post directly to their friends’
Facebook Walls without having to exit the app. In addition to this being a useful feature for our users, we
automatically gain free advertising for Birthday Reminder. Every Facebook post via a third-party app
includes a direct link back to the originating app. This helps to publicize Birthday Reminder every time any
of our users post Happy Birthday messages to their Facebook friends.
We’ll also make it easy for our user to call, SMS, or e-mail birthday wishes to friends imported from the
Address Book.
The competition
We have our app idea, but before we get into the design and coding stages, now might be a good time to
take a look at the competition.
It’s always worth looking at your app’s most successful competitors at the beginning of a project.
Search the App Store for your target keywords. Which apps regularly come up at the top of the search list?
Typically, those are the apps getting the most downloads. What are these successful competitors doing
right? It is likely to be a combination of the following:
They have a great icon.
They’ve built a great app.
They’ve designed a beautiful UI (user interface).
Their app is easy to use and has an intuitive user experience.
They’ve integrated social networking into their app effectively.
They’ve run a strong marketing campaign.
They’ve been featured by Apple in the App Store.
They’ve got lots of 4- and 5-star ratings.
They had the idea first and launched ahead of the competition.
The last point in this list is often one of the most likely scenarios. A great number of those app makers who
got into the App Store early with a good idea are still holding strong in their category. Being in the top 100
[...]... Planning Our App Figure 1-2 iOS GUI PSD by Teehan+Lax Retina displays, the status bar, and the iPhone5 The iPhone screen pre -iPhone 5 is 320480 points This is the same for both retina and non-retina screens Points are different from pixels In Objective-C, every reference to the size or the position of a view is measured in points The iPhone5 screen is 320 56 8 points Prior to the iPhone 4, each point was... and Planning Our AppIniOS 5, Apple added Appearance APIs, which have continued to evolve in iOS6 These APIs make skinning Apple’s UI components much easier than with previous versions of the iOSSDK Birthday Reminder will exploit these features to full effect The design concept of using a birthday cake for our icon is also prominent throughout the main views of our app, such as the home view and import... of a single pixel With retina displays, however, there are four pixels squeezed into every point (22 grid), resulting in the dimensions of aniPhone 4 or iPhone 4s retina display being a total of 64 0 960 pixels (see Figure 1-3) The iPhone5 screen packs in 64 011 36 pixels (see Figure 1-3) The status bar is 20 points high, and therefore 40 pixels high on a retina display I’d suggest always including... versions of the iOS simulator are downloaded in the background as required (for example, if your app needs to support iOS 4 or 5, Apple provides iOS simulators to enable you to run and check your appin older versions of iOS) Registering as an Apple developer There are two stages of registration required before we can test our app on aniPhone and submit apps to the App Store: Registering as an Apple developer,... your App Store apps Submitting new apps and app updates to the App Store is handled by iTunes Connect In addition, developers log in to iTunes Connect to manage: Bank and tax info/contracts Sales trends and reports The Apple Developer Forums provide a great online resource for iOS and Mac software programming questions 24 Provisioning Our App for Development Before you can get access to these iOS. .. 1-7b), and then save the birthday data, friend names, and profile icon URLs locally into our Core Data store 15 Chapter 1 Figure 1-7 (a) Handling Facebook authorization (b) Preparing to import birthdays from Facebook Prior to iOS 6, Facebook enabled and encouraged iOS developers to integrate social features into iOS apps In iOS 6, Apple has now partnered with Facebook to include Facebook’s Single Sign-On... designing for iOS apps Thanks to the talented folk over at Teehan+Lax, designers have access to a very handy PSD file with all of the native iOS controls mocked up into Photoshop layers in a single iOS GUI (graphical user interface) PSD file This makes an ideal starting point when designing for iOS The PSD is free to download from www.teehanlax.com/downloads (see Figure 1-2) 8 Designing and Planning... icon and the first few words of your App Store title when scrolling through the rows and rows of competitor apps Avoid being too obscure with your App Store title You should include the keywords you’d expect users to search and find your app The App Store search algorithm gives a good amount of importance to the 6 Designing and Planning Our App words inapp titles Unless you already have a strong brand... results and e-mail them to my designer with detailed instructions to mock up the final designs in Photoshop The designer then creates 64 0 960 pixel retina-ready PSD files for each view of the app 10 Designing and Planning Our App When working with clients, insist that the design be signed off before you start coding their app Clients often fight this requirement, claiming that their app is a work in progress,... distributed by Apple for free via the Mac App Store The first thing to do is open the App Store on your Mac, and then download and install Xcode straight from the store You’ll need to be working on an Intel-based Mac running Lion or Mountain Lion to install Xcode 4 .5 (or greater) While Xcode downloads and installs in the background, you can just keep reading Here’s a direct link to Xcode in the US Mac App Store: . Development:
Build An iPhone App in 5 Days with iOS 6 SDK
Foundation iPhone App Development: Build an iPhone App in 5 Days with iOS 6 SDK
details tried and tested. Portfolio Pro
for iPad—Brandable Photo and Video App. Including a strapline in your title improves your chances of
appearing in relevant App Store searches.