Published by Sams
What You'll Learn
- What makes an iPad an iPad
- Where to get the tools you need to develop for the iPad
- How to join the iPhone OS Developer Program
- The need for (and use of) provisioning profiles
- What to expect during the first few hours of this book
The iPad is the next step in Apple's touch-based platform, iPhone OS. Sporting a larger screen and faster processor than the iPhone, the iPad brings desktop-level computing to a very portable and flexible platform. If you're an iPhone developer, the iPad gives you the ability to think bigger—to imagine your applications in a whole new way. For those just starting out, it offers a robust toolset for realizing your touch-enabled computing ideas.
This hour will get you prepared for iPad development. You're about to embark on the road to becoming an iPad developer, but there's a bit of prep work before you start coding.
Welcome to the iPad Platform
If you're reading this book, you probably already have an iPad, and that means you already understand how to interact with its interface. Crisp graphics, amazing responsiveness, multitouch, and thousands of apps—this just begins to scratch the surface. As a developer, however, you'll need to get accustomed to dealing with a platform that, to borrow a phrase from Apple, forces you to "think different."
Display and Graphics
The iPad screen is 1024x768 pixels—giving you a large amount of space to present your application's content and interface (see Figure 1.1). Although this resolution might seem limiting, consider that desktop computers only recently exceeded this size and many websites are still designed for 800x600. In addition, the iPad's display is dedicated to the currently running application. You will have one window to work in. You can change the content within that window, but the desktop and multiwindow application metaphors are gone.
The iPad has a screen resolution of 768x1024 (portrait), 1024x768 (landscape).
The lack of multiple windows shouldn't be considered a flaw, however. Apple provides plenty of interface alternatives that will help you display just as much information as a traditional multiwindow desktop application, but in a more structured way.
The graphics that you display on your screen can include complex animated 2D and 3D displays thanks to the OpenGL ES implementation. OpenGL, an industry standard for defining and manipulating graphic images, is widely used to create games.
Application Resource Constraints
The iPad, by all accounts, is a snappy device. It is also the first device in many years to use an Apple-branded processor: the A4. The A4 is a "system on a chip" that provides CPU, GPU, and other capabilities to the device. The specs of the processor will eventually become clearer, but are still mostly guesswork at the time of this writing.
Apple has gone to great lengths to keep the iPad responsive, no matter what you're doing. Unfortunately, this has led to one of the biggest drawbacks of the system—only a single third-party application can run at a time. This means that your program must provide the features users need without forcing them to jump into other apps. It also means that your application must remain active to communicate with the user. Although push notifications are possible, no actual processing can take place when your application has exited. The good news? This will change in late 2010 when the iPad adopts iPhone OS 4.0.
Another constraint that you need to be mindful of is the available memory. The iPad contains 256MB of dedicated application RAM—hardly astronomical, and no chance for an upgrade in the future!
Note - Throughout the book, you'll see reminders to "release" memory when you're done using it. Even though you might get tired of seeing it, this is a very important process to get used to.
The iPad's connectivity options mirror the iPhone and iPod Touch. The 3G iPad, for example, has the ability to always be connected via a cellular provider (such as AT&T in the United States). This wide-area access is supplemented with built-in WiFi and Bluetooth in all iPad models. WiFi can provide desktop-like browsing speeds within the range of a wireless hot spot. BlueTooth, on the other hand, can be used to connect a variety of peripheral devices to your iPad, including a keyboard!
As a developer, you can make use of the Internet connectivity to update the content in your application, display web pages, or create multiplayer games. The only drawback is that applications that rely heavily on 3G data usage stand a greater chance of being rejected from the App Store. These restrictions have been lessened in recent months, but it is still a point of frustration for developers.
Input and Feedback
The iPad shines when it comes to input and feedback mechanisms and your ability to work with them. You can read the input values from the capacitive multitouch (four-finger!) screen, sense motion and tilt via the accelerometer, determine where you are using the GPS (3G model), and even determine which way you're facing with the digital compass (3G model). The iPad itself can provide so much data to your application about how and where it is being used that the device itself truly becomes a controller of sorts—much like the Nintendo Wii.
Finally, for each action your user takes when interacting with your application, you can provide feedback. This, obviously, can be visible text on the screen, or it can be high-quality audio and video. As a developer, you can incorporate all of these capabilities, and in this book you'll learn how!
That wraps up our quick tour of the iPad platform. After years of feeling cramped by the iPhone's display, developers can now explore full-screen high-resolution applications—all with the same capabilities found on the successful iPhone platform.
Tip - Although this book targets the iPad specifically, much of the information also applies to the iPhone and iPod Touch. These systems differ in capabilities, such as support for a camera and GPS, but the development techniques are otherwise identical.
Becoming an iPad Developer
Obviously, there is more to being an iPad developer than just sitting down and writing a program. You need a modern Intel Macintosh desktop or laptop running Snow Leopard, and at least 6GB of free space on your hard drive. The more screen space you have on your development system, the easier it will be to switch between the coding, design, simulation, and reference tools that you'll need to be using. That said, I've worked perfectly happily on a 13" MacBook Pro, so an ultra-HD multimonitor setup certainly isn't necessary.
So, assuming you already have a Mac, what else do you need? The good news is that there isn't much more, and it won't cost you a cent to write your first application.
Joining the Apple Developer Program
Despite somewhat confusing messages on the Apple website, there really is no fee associated with joining the Apple Developer Program, downloading the iPhone OS SDK (Software Development Kit), writing iPad applications, and running them on Apple's iPhone OS simulator.
There are limitations, however, to what you can do for free. If you want to have early access to beta versions of the iPhone OS and SDK, you'll need to be a paid member. If you want to load the applications you write on a physical iPad device or distribute them on the App Store, you'll also need to pay the membership fee. Most of the applications in this book will work just fine on the simulator provided with the free tools, so the decision on how to proceed is up to you.
Tip - If you aren't yet sure if the paid program is right for you, you can upgrade at any time. I recommend starting out with the free program and upgrading after you've had a chance to write a few sample applications and to run them in the simulator.
Obviously, things such as motion sensor input and GPS readings can't be accurately presented in the simulator, but these are special cases and won't be needed until later in this book.
If you choose to pay, the paid Developer Program offers two levels: a standard program ($99) for those who will be creating applications that they want to distribute from the App Store, or an enterprise program ($299) for larger companies wanting to develop and distribute applications in-house but not through the App Store. Chances are, the standard program is what you want.
Note - The standard ($99) program is available for both companies and individuals. If you want to publish to the App Store with a business name, you'll be given the option of choosing a standard "individual" or "company" program during the registration.
Registering as a Developer
Big or small, free or paid, your venture into iPad development begins on Apple's website. To start, visit the Apple iPhone Dev Center (http://developer.apple.com/iphone), shown in Figure 1.2.
If you already have an Apple ID from using iTunes or other Apple services, congratulations, you're almost done! Use the Log In link to access your account, agree to Apple's developer terms, and provide a few pieces of additional information for your developer profile. You'll immediately be granted access to the free developer resources!
Visit the iPhone Dev Center to log in or start the enrollment process.
If you don't yet have an Apple ID, click the Register link, followed by Get Started on the subsequent page. When the registration starts, choose Create an Apple ID in the first step, as shown in Figure 1.3.
You'll use an Apple ID to access all the developer resources.
The registration process walks you through the process of creating a new Apple ID, and collects information about your development interests and experience, as shown in Figure 1.4.
After the registration is complete, Apple will verify your email address by sending you a clickable link to activate your account.
The multistep registration process collects a variety of information about your development experience.
Joining a Paid Developer Program
Once you have a registered and activated Apple ID, you can make the decision to join a paid program, or continue using the free resources. If you choose to join a paid program, again point your browser to the iPhone Dev Center (http://developer.apple.com/iphone) and click the Register button. Choose Use an Existing Apple ID for the Developer Program option, visible in Figure 1.3.
On the page that appears, look for the Join Today link and click it. The registration tool will now guide you through applying for the paid programs, including choosing between the standard and company options, as shown in Figure 1.5.
Choose the paid program that you want to apply for.
Unlike the free Developer Membership, the paid Developer Program does not take effect immediately. When the App Store first launched, it took months for new developers to join and be approved into the program. Today, it may take hours or a few days—just be patient. You can check your current status at any time by logging in to the iPhone Dev Center and following the Check Your Enrollment Status Now link.
Use the Register link to create a new free Developer Membership, or follow the links in the iPhone OS Developer Program section (currently http://developer.apple.com/iphone/program) to join a paid program.
Installing the iPhone OS Developer Tools
After you've registered your Apple ID, you can immediately download the current release version of the iPhone OS developer tools directly from the iPhone Dev Center (http://developer.apple.com/iphone). Just click the Download link and sit back while your Mac downloads the massive (~2.5GB) SDK disk image.
Tip - If you have the free Developer Membership, you'll likely only see a single SDK to download—the current release version of the development tools. If you've become a paid program member, you may see additional links for different versions of the SDK (3.2, 3.5, 4.0, and so on). The examples in this book are based on the 3.2+ series of SDKs, so be sure to choose that option if presented.
When the download completes, open the resulting disk image, and double-click the Xcode and iPhone SDK for Snow Leopard icon. This will launch the Mac OS X Installer application and assist you in the installation. There is no need to change any of the defaults for the installer, so just read and agree to the software license and click Continue to proceed through the steps.
Unlike most applications, the Apple developer tools are installed in a folder called Developer located at the root of your hard drive. Inside the Developer folder are dozens of files and folders containing developer frameworks, source code files, examples, and of course, the developer applications themselves. Nearly all your work in this book will start with the application Xcode, located in the Developer/Applications folder (see Figure 1.6).
Most of your work with the developer tools will start in the Developer/Applications folder.
Although we won't get into real development for a few more hours, we will be configuring a few options in Xcode in the next section, so don't forget where it is!
Creating a Development Provisioning Profile
Even after you've obtained an Apple Developer Membership, joined a paid Developer Program, and downloaded and installed the iPhone OS development tools, you still won't be able to run applications that you write on your iPad! The reason for this is that you haven't created a development provisioning profile.
In many development guides, this step isn't covered until after development begins. In my mind, once you've written an application, you're going to want to immediately run it on the iPad. Why? Because it's just cool to see your own code running on your own device!
What Is a Development Provisioning Profile?
Like it or not, Apple's current approach to iPhone OS development is to make absolutely certain that the development process is controlled—and that groups can't just distribute software to anyone they please. The result is a rather confusing process that ties together information about you, any development team members, and your application into a "provisioning profile."
A development provisioning profile identifies the developer who may install an application, an ID for the application being developed, and the "unique device identifiers" for each iPad that will run the application. This is only for the development process. When you are ready to distribute an application via the App Store or to a group of testers (or friends!) via ad hoc means, you'll need to create a separate "distribution" profile. Because we're just starting out, this isn't something you'll need right away. We talk more about distribution profiles in Hour 24, "Distributing Applications Through the App Store."
Generating and Installing a Development Provisioning Profile
Creating a provisioning profile can be frustrating and seem outrageously convoluted. Apple has streamlined the process tremendously with an online Development Provisioning Assistant, but we still have to jump through some hoops. Let's bite the bullet, and get through this!
Getting Your iPad Unique Device Identifier
To run your application on a real iPad, you'll need the ID that uniquely identifies your iPad from the thousands of other iPads. To find this, first make sure that your device is connected to your computer, and then launch Xcode from the Developer, Applications folder. When Xcode first launches, immediately choose Window, Organizer from the menu. The Organizer utility slightly resembles iTunes in its layout. You should see your iPad listed in the far left column of the Organizer under the Devices section. Click the icon to select it, then click the "Use for Development" button. Your screen should now resemble Figure 1.7.
First, grab the ID of your iPad.
The Identifier field is the unique device ID that we're looking for. Go ahead and copy it to the Clipboard. You'll need to paste it into the Provisioning Assistant shortly.
Starting the Provisioning Assistant
Next, head to the Apple website and the iPhone Dev Center (http://developer.apple.com/iphone). Make sure that you've logged in to the site, and then click the iPhone Provisioning Portal link, currently located in the upper-right side of the page. The Provisioning Portal is designed to give you access to the tools you need to create provisioning and distribution profiles. It also includes the Development Provisioning Assistant, which is the web utility that will make our lives much easier. Click the Launch Assistant button (see Figure 1.8).
Head to the iPhone Provisioning Portal, and then launch the Development Provisioning Assistant.
The assistant will launch in your web browser and display a short splash screen. Click the Continue button to begin.
Choosing an App ID
Your first step is to choose an App ID. This ID will identify a shared portion of the keychain that your application will have access to.
The keychain is a secure information store on the iPad that can be used to save passwords and other critical information. Most apps don't share a keychain space (and therefore can't share protected information). If you use the same App ID for multiple applications, however, they can share keychain data.
For the purposes of this book, there's no reason the tutorial apps can't share a single App ID, so create a new ID named anything you want. If you have already created App IDs in the past, you'll be given the option to choose an existing ID. I'm creating a new App ID, Tutorials, as shown in Figure 1.9. Enter the ID and click Continue to move on.
An App ID can be used for a single application or group of applications.
Assigning a Development Device
Next you are asked to assign a development device, as shown in Figure 1.10. This is the device ID that identifies which iPad will be allowed to run the applications you create. Enter a meaningful description for the device (Johns WiFi iPad, for example), and then paste the string you copied from the Xcode organizer into the Device ID field. Click Continue to move on.
Assign a device that can run your application.
Note that as with the App IDs, if you've already used a device ID in the past, you will be given the option of simply selecting it from a drop-down list.
Generating a Certificate Signing Request
Now things are getting fun. The next step takes place outside of your browser. Leaving the Development Provisioning Assistant open, go to the Applications, Utilities folder on your hard drive and open the Keychain Access utility. Choose Keychain Access, Certificate Assistant, Request a Certificate from a Certificate Authority from the menu (see Figure 1.11).
In this step, you create a certificate request that is uploaded to Apple.
The Keychain Access Certificate Assistant will start. Thankfully, this is a pretty short process. You just need to enter your email address, name, and highlight the Saved to Disk option, as shown in Figure 1.12.
Enter the information needed for the certificate request. You can leave the CA Email Address field empty.
Click Continue to save the certificate to your disk. Make sure you make a note of where you save the certificate, because you're going to be uploading it to Apple back in the Development Provisioning Assistant. Once you save it, you can close the Certificate Assistant window.
Uploading the Certificate Signing Request
Return to the Development Provisioning Assistant in your web browser. Click continue until you are prompted to submit the certificate signing request that you just generated (see Figure 1.13). Use the Choose File button to select the request file, and then click Continue to upload it.
Naming and Generating the Provisioning Profile
We're almost done! After uploading the request, you'll be prompted to name the provisioning profile (see Figure 1.14). Because this profile contains information that can potentially identify individual phones and applications, you should choose something relevant to how you intend to use it. In this case, I'm only interested in using it as a generic development profile for all of my apps, so I'm naming it iPad Development Profile. Not very creative, but it works.
Upload the certificate signing request to Apple.
Name the profile to reflect how you intend to use it.
Click the Generate button to create your provisioning profile. This may take 20 to 60 seconds, so be patient. The screen will eventually refresh to show the final profile information, as shown in Figure 1.15.
After several seconds, the profile is generated.
Our final steps will be downloading and installing the profile, and downloading and installing a security certificate that will be associated with the profile.
Downloading the Development Provisioning Profile and Certificate
At this point, your profile has been generated, along with a security certificate that can be used to uniquely associate your applications with that profile. All that remains is downloading and installing them. Click the Continue button to access the provisioning profile download screen, as shown in Figure 1.16. Click the Download Now button to save the profile to your Downloads folder (file extension .mobileprovision).
As much as I hate to say it, the next thing to do is to ignore the onscreen instructions—the installation process that Apple describes in the assistant isn't the most efficient route. Instead, click the Continue button until you are given the option of downloading the development certificate, as shown in Figure 1.17.
Click the Download Now button to download the certificate file (file extension .cer) to your Downloads folder. You are now finished with the Provisioning Assistant and can safely exit.
Download the provisioning profile.
Download the development certificate.
Installing the Development Provisioning Profile and Certificate
To install the profile and certificate, we just need to exercise our double-click skills. First, install the development certificate by double-clicking it. Doing so opens Keychain Access and prompts you for the keychain where the certificate should be installed. Choose the login keychain, and then click OK, as demonstrated in Figure 1.18.
Choose the login keychain to hold your development certificate.
After adding the certificate, you should be able to browse through your login keychain for a key labeled with your name that contains the certificate.
To install the development profile, double-click the downloaded .mobileprovision file. Xcode will launch—if it isn't already running—and silently install the profile. You can verify that it has been successfully installed by launching the Organizer within Xcode (Window, Organizer) and then clicking the Provisioning Profiles item within the iPhone Development section, as shown in Figure 1.19.
If the profile has been successfully installed, it should be listed in the Xcode Organizer.
Tip - Once you have a development machine configured, you can easily configure other computers using the "Developer Profile" item in the Xcode organizer. The "Export Developer Profile" and "Import Developer Profile" buttons will export (and subsequently import) all your developer profiles/certificates in a single package.
But Wait...I Have More Than One iPhone OS Device! - The Development Provisioning Assistant helps you create a provisioning profile for a single iPad, iPhone, or iPod Touch device. But, what if you have multiple devices that you want to install onto? No problem. You'll need to head back to the iPhone Provisioning Portal and click the Devices link listed on the left side of the page. From there, you can add additional devices that will be available to your profile.
Next, click the Provisioning link, also on the left side of the page, and use the Edit link to modify your existing profile to include another iPad, as demonstrated in Figure 1.20.
Finally, you'll need to use the Download link to redownload the modified profile and then import it into Xcode so that the additional device is available.
Add additional devices to a provisioning profile within the web portal. Remember to redownload the profile and install it!
Testing the Profile with an iPad App
It seems wrong to go through all of that work without some payoff, right? For a real-world test of your efforts, let's actually try to run an application on your iPad. If you haven't downloaded the project files to your computer, now would be a good time to visit http://www.teachyourselfipad.com and download the archives.
Within the Hour 1 Projects folder, open the Welcome folder. Double-click Welcome.xcodeproj to open a very simple application in Xcode. After the project opens, your display should be similar to Figure 1.21.
Open the Welcome.xcodeproj in Xcode.
Next, make sure that your iPad is plugged into your computer. Using the menu in the upper-left corner of the Xcode window, choose iPhone Device 3.2 (or a later version, if available). This will tell Xcode that when the project is built, it should be installed on your iPad. Finally, click Build and Run.
After a few seconds, the application should be installed and launched on your iPad, as you can see in Figure 1.22.
Congratulations, you've just installed your first home-grown iPad application!
You can now exit Xcode and quit the Welcome application on your iPad.
Note - When you clicked Build and Run, the Welcome application was installed and started on your iPad. It will remain there until you remove it manually. Just touch and hold the Welcome icon until it starts wiggling, then delete the application as you would any other.
Developer Technology Overview
Over the course of the next few hours, you will be introduced to the technologies that you'll be using to create iPad applications. Our goal is to get you up to speed on the tools and technology, and then you can start actively developing. This means you're still a few hours away from writing your first app, but when you start coding, you'll have the necessary background skills and knowledge to successfully create a wide variety of applications.
The Apple Developer Suite
In this chapter, you downloaded and worked with the Xcode application. This is just one piece (albeit a very important piece) of the developer suite that you will be using throughout this book. Xcode, coupled with Interface Builder and the iPhone Simulator, will make up your development environment. These three applications are so critical, in fact, that we've devoted two hours (2 and 4) to covering them.
It's worth mentioning that almost every iPad, iPhone, iPod, and Macintosh application you run, whether created by a single developer at home or a huge company, is built using the Apple developer tools. This means that you have everything you need to create software as powerful as any you've ever run.
Later in the book, you'll be introduced to additional tools in the suite that can help you debug and optimize your application.
Objective-C is the language that you'll be using to write your applications. It will provide the structure for our applications, and be used to control the logic and decision making that goes on when an application is running.
If you've never worked with a programming language before, don't worry. We cover everything you need to get started in Hour 3, "Discovering Objective-C." Developing for the iPad in Objective-C is a unique programming experience, even if you've used other programming languages in the past. The language is unobtrusive and structured in a way that makes it easy to follow. After your first few projects, Objective-C will fade into the background, letting you concentrate on the specifics of your application.
While Objective-C defines the structure for iPad applications, Cocoa Touch defines the functional building blocks, called classes, that can make the iPad do certain things. Cocoa Touch isn't a "thing," per se, but a collection of interface elements, data storage elements, and other handy tools that you can access from your applications.
As you'll learn in Hour 4, "Inside Cocoa Touch," you can access literally hundreds of different Cocoa Touch classes and you can do thousands of things with them. We cover quite a few of the most useful classes in this book and give you the pointers you need to explore even more on your own.
The iPhone OS platform and Macintosh use a development approach called Model-View-Controller (MVC) to structure applications. Understanding why MVC is used and the benefits it provides will help you make good decisions in structuring your most complex applications. Despite the potentially complicated-sounding name, MVC is really just a way to keep your application projects arranged so that you can easily update and extend them in the future. We look more at MVC in Hour 6, "Model-View-Controller Application Design."
This hour introduced you to the iPad, its capabilities, and its limitations. You learned about the iPad's display, networking, and other features that can be used to create unique user experiences. We also discussed the Apple developer tools, how to download and install them, and the differences between the varying pay-for developer programs. To prepare you for actual on-device development, you explored the process of creating and installing a development provisioning profile in Xcode and even installed an application on your iPad.
The hour wrapped up with a quick discussion of the development technologies that will make up the first part of the book and form the basis for all the iPad development you'll be doing.
I thought the iPad had at minimum 16GB of RAM in the low-end and 64GB on the high-end model. Doesn't it?
- The "memory" capabilities for the iPad that are advertised to the public are the storage sizes available for applications, songs, and so forth. It is separate from the RAM that can be used for executing programs. If Apple implements virtual memory in a future version of iPhone OS, it is possible that the larger storage could be used for increasing available RAM.
What platform should I target for development?
- That depends on your goals. If you want to reach the largest audience, consider a universal application that works on the iPad, iPhone, and iPod Touch. We examine this development possibility later in Hour 22, "Building Universal Applications." If you want to make use of the most capable hardware, you can certainly target the unique capabilities of the 3G iPad, but you will potentially be limiting the size of your customer base.
Why isn't the iPad (and iPhone OS platform) open?
- Great question. Apple has long sought to control the user experience so that it remains "positive" regardless of how users have set up their device, be it a Mac, an iPad, or an iPhone. By ensuring that applications can be tied to a developer and enforcing an approval process, Apple attempts to limit the potential for a harmful application to cause damage to data or otherwise negatively impact the user. Whether this is an appropriate approach, however, is open to debate.
- What is the resolution of the iPad screen?
- What is the cost of joining an individual iPhone OS Developer Program?
- What language will you use when creating iPad applications?
- 1024x768. The iPad screen resolutions are identical across the platform variants.
- The Developer Program costs $99 a year for the individual option.
- Objective-C will be used for iPad development.
- Establish an Apple Developer Membership and download and install the developer tools. This is an important activity that, if you didn't follow along in the course of the hour, should be completed before starting the next hour's lesson.
- Review the resources available in the iPhone Dev Center. Apple has published several introductory videos and tutorials that helpfully supplement what you'll learn in this book.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.