Docsity
Docsity

Prepare-se para as provas
Prepare-se para as provas

Estude fácil! Tem muito documento disponível na Docsity


Ganhe pontos para baixar
Ganhe pontos para baixar

Ganhe pontos ajudando outros esrudantes ou compre um plano Premium


Guias e Dicas
Guias e Dicas


iPhone Development: Getting Started, Manuais, Projetos, Pesquisas de Cultura

An introduction to iphone development using the sdk, including user interface ideas, product definition statement, and image decoration mechanism. It also covers topics such as creating a second button, setting the view's background color, adding a toolbar to a view controller, and replacing the image view interface builder.

Tipologia: Manuais, Projetos, Pesquisas

2011

Compartilhado em 23/11/2011

daniel-vieira-25
daniel-vieira-25 🇧🇷

2 documentos

1 / 249

Toggle sidebar

Esta página não é visível na pré-visualização

Não perca as partes importantes!

bg1
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Pré-visualização parcial do texto

Baixe iPhone Development: Getting Started e outras Manuais, Projetos, Pesquisas em PDF para Cultura, somente na Docsity!

MEAP Edition Manning Early Access Program

Copyright 2010 Manning Publications

For more information on this and other Manning titles go to www.manning.com

3.2.3 Notification/Observers 3.3 User Interface Guidelines and Inspiration 3.3.1 Apple Human Interface Guidelines 3.3.2 Product Definition Statement 3.4 Laying Out UI in the Interface Builder 3.4.1 Mock-Up (Hello iPhone) 3.4.2 Nailing it Down 3.5 UI Cooperation with IB and XCode 3.5.1 Wiring to the UI 3.5.2 Programmatic Changes 3.5.3 Adapting Your Interface Dynamically 3.6 Summary

Part 2 The iPhone Techniques

  1. Using View Controllers and Images in PicDecor 4.1 UI Design Concepts 4.1.1 Building Blocks that can be Customized 4.1.2 Product Definition Statement 4.1.3 Think Outside the Box 4.1.4 Think Apple 4.2 Creating View Controllers and other Widgets 4.2.1 Technique 1: Designing a View Controller in Interface Builder 4.2.2 Technique 2: Adding an ImageView and Toolbar to a View 4.2.3 Technique 3: Adding Buttons to a View 4.3 Developing Actions and Outlets 4.3.1 Technique 4: Declaring Actions and Outlets in Xcode 4.3.2 Technique 5: Connecting Actions and Outlets to Code in IB 4.4 Using the Camera/Photo Album 4.4.1 Technique 6: Adding Camera/Photo Album Access 4.4.2 Technique 7: Presenting a View Controller Modally 4.4.3 Technique 8: Dismissing a Modally Displayed View Controller 4.5 Displaying and Handling Images 4.5.1 Interact with the Process as it Goes 4.5.2 Technique 9: Displaying Selected Images 4.5.3 Technique 10: Detecting a Device Without a Camera 4.6 Providing Email Capabilities 4.6.1 Technique 11: Adding In-App Email 4.6.2 Technique 12: Scaling and Image for Email 4.6.3 Technique 13: Using the Activity Indicator 4.7 Summary
  2. Accessing the Address Book/Contacts in Dial 5.1 Creating a Navigation-based Project with a Table View 5.1.1 Technique 1: Creating a Navigation-based Application

5.2 Presenting Data Using a Table View 5.2.1 Technique 2: Displaying Data in a Table View 5.2.2 Apple Cell Styles 5.2.3 Cell Customization 5.2.4 Technique 3: Handling Table View Cell Selection 5.3 Accessing the Address Book 5.3.1 Technique 4: Retrieving the Address Book Entries 5.3.2 Technique 5: Obtaining the Image Property from an Address Book Entry 5.3.3 Technique 6: Obtaining Grouped Properties from the Address Book 5.3.4 Technique 7: Making a Call 5.3.5 Technique 8: Displaying Address Book Record Details 5.4 Managing Table Data 5.4.1 Technique 9: Deleting and Rearranging Table View Rows 5.4.2 Technique 10: Filtering Displayed Table View Data 5.5 Summary

  1. MapKit and the Camera in WhereAmIParked 6.1 Using Maps with the User's Location 6.1.1 Technique 1: Adding a MapView to a Project 6.1.2 Technique 2: Centering and Zooming a MapView 6.1.3 Technique 3: Finding the User's Location via CoreLocation 6.2 Displaying Details on MapView Locations and Storing Users' Notes 6.2.1 Technique 4: Displaying MapView Pins 6.2.2 Technique 5: Storing and Retrieving the User's Location 6.2.3 Technique 6: Reverse Geocoding 6.2.4 Technique 7: Adding Pin Callouts 6.2.5 Technique 8: Typing and Storing Users' Note 6.3 Storing, Retrieving and Displaying Camera Images 6.3.1 Technique 9: Adding a Camera Control 6.3.2 Technique 10: Receiving and Storing the Picture 6.3.3 Technique 11: Displaying a Picture 6.4 Summary
  2. Settings, Audio and Shake Detection in TimeDown 7.1 Settings Bundles in iPhone Projects 7.1.1 Technique 1: Adding Settings to an Xcode Project 7.1.2 Technique 2: Initializing iPhone Settings 7.1.3 Technique 3: Accessing Settings Value in an App 7.1.4 Technique 4: Setting the App Settings Icon 7.2 Runtime and Time-Based UI Changes 7.2.1 Technique 5: Rounding Corners of a View 7.2.2 Technique 6: Updating the UI with a Repeating Timer 7.3 Playing Audio and Vibrating the Device 7.3.1 Technique 7: Playing an MP3 File 7.3.2 Technique 8: Vibrating the iPhone 7.4 Detecting and Handling Device Motion

10.3.1 Technique 8: Matching Players 10.3.2 Sending Invitations 10.3.3 In-Game Voice Chat 10.4 Summary

  1. Animation, HTTP Request, XML and Web Page Displaying - ReadNShare
  2. iPad Conversion, iAd and Sharing on Social Networks - ReadNShare

The iPhone is so much more than a phone that it should hardly be called a phone at all. It's really a portable computer that makes phone calls. Complete with internet access, applications more like a desktop than any other device out there as well as music and video, the iPhone is really a small, but powerful computer. The iPod Touch is basically a subset of the iPhone. It doesn't make calls, have a camera and has a few other limitations. They both run the iPhone OS and in most cases I consider them the same in this book. Since the iPhone seems more prevalent and the name is used more commonly, I'll most often refer to the iPhone and mean both devices. Being a computer, the iPhone runs software - very cool and useful software. The software developed for the iPhone is unique for various reasons. One big reason is because the iPhone is unique. Let's briefly summarize a few things that make iPhone special -- for both users and developers. The user experience on an iPhone is unique and innovative. Unlike most phones, the iPhone has a touch screen. There are several out now, but mobile touch screes are still relatively new. On top of that, the iPhone's use of the touch screen is smooth and natural compared to other phones on which I've tested and developed. I believe Apple has taken what they've done for the general user's experience and built on top of that in their current product offering including the development environment. The environment is clean, intuitive and makes for a great experience for the developer leading to the same for the end user. Bottom line: people love to use the iPhone and iPod Touch. And I believe it's a combination of the interface experience with the many amazing apps developed for the interface and the hardware. The iPhone is not only a pretty nice little computer that fits in your pocket and

iPhone Development: Getting Started

Please post comments or corrections to the Author Online forum: http://www.manning-sandbox.com/forum.jspa?forumID=

coding in Java. The computers to do it are cheaper than Macs. But again, I think the fanatics want what they want, it's visually appealing, it's fun and there's money to be made. While there are some advantages to Blackberry development (e.g., business - there's still more Blackberries out there than iPhones, Java/J2ME), I don't believe the Blackberries have the user experience and appealing UI the iPhone has for the user and developer. Blackberry owners are addicted to their Blackberries (Crackberries), but iPhone users love their iPhones. With the variety of libraries out there for iPhone development including OpenGLES and more, writing a graphic intensive game on the iPhone is more reasonable on the iPhone. Similarly, Java will probably never have the performance as a truly compiled language -- especially not on a more limited processor device. The iPhone SDK is written for the iPhone. Blackberry has a specific J2ME SDK, but it's still a flavor of J2ME which is just limited Java. Blackberry does a great job at what it does, but it's still somewhat of a limited development environment. Whether it's the device itself, the capabilities of the device, the SDK, the apps or the UI, people are excited to use the device, buy apps and make apps (for fun or profit). Let's create a simple app and see just how Apple helps in some ways.

We'll start with a "Hello World" project. This is not only a useful and simple project to introduce you to iPhone development, but also shows how easy it is to create a basic project in Xcode. Apple has made many things easy to get started including Xcode. If you haven't downloaded and installed the latest Xcode version, do so by going here: http://developer.apple.com/TOOLS/Xcode/

NOTE DEFINITION iPhone Developer Program - The iPhone Developer Program provides a complete and integrated process for developing and distributing applications for iPhone and iPod touch.

You also need the iPhone SDK downloaded and installed. If you haven't joined the iPhone Developer Program, you can register for free here: http://developer.apple.com/iphone/program/start/register/ (NOTE: This does not

1.2 Creating Your First App

Please post comments or corrections to the Author Online forum: http://www.manning-sandbox.com/forum.jspa?forumID=

allow you full access to all of the benefits of the iPhone Developer Program, but does give you access to the SDK).

NOTE Objective-C For the following example and many of the projects in this book you don't need extensive knowledge of Objective-C - the code is laid out for you. However, you will, of course, need to be very familiar with Objective-C moving forward in iPhone development. Objective-C is similar to C++ and puts memory management largely on the developer. There are many resources for learning Objective-C including Manning's "Objective-C for the iPhone." I recommend that you invest some time becoming familiar with the language before tackling projects on your own.

Now that we've set up our development tools, let's put them to use.

In this section we'll start our "Hello World" but we'll finish in chapter 3. Here our main goal is to create project and run it in the iPhone Simulator. So to avoid going further into the Interface Builder and deeper concepts, let's just create the default app. Start Xcode (either by navigating to the application in the Finder as in figure 1.1 or pressing (Apple key)+spacebar to start Spotlight, typing Xcode and pressing Enter).

Figure 1.1 Locating the Xcode Application in the Mac OS X Finder

Once Xcode is started, click on the File menu and “New Project...” under that. In the “New Project” form, ensure Application under the iPhone group is selected and double click on “View-based Application” on the right (see figure 1.2).

1.2.1 Hello iPhone World

Please post comments or corrections to the Author Online forum: http://www.manning-sandbox.com/forum.jspa?forumID=

You can now build and run your app in the iPhone Simulator by clicking Run->”Go (Debug)” (or pressing (Apple key)+Enter). What you'll see isn't very impressive (see figure 1.3).

Figure 1.3 Initial Execution of a View-Based Application in the iPhone Simulator

Please post comments or corrections to the Author Online forum: http://www.manning-sandbox.com/forum.jspa?forumID=

However unimpressive that might be, it is an app, it runs in the simulator and could be installed on an iPhone/iPod Touch and run there also. It even has a (blank) icon. Now we know how to create an unimpressive app, I'll tell you about some of the ways Apple supports you in making impressive apps.

Once you see the tools given to you by Apple and others, your head will begin to spin out of control with the limitless possibilities of apps you can build. And while Apple says “there's an app for that” there's always new apps and new needs to fill to build more and more. Most apps are built using framework objects provided in the SDK including the tableview for lists, imageview for images and webview for loading server pages just to name a few. These and many other objects give you significant functionality with minimal work and are provided by the SDK frameworks. You'll use the various frameworks to create your iPhone apps. Some will become second nature to you and some you may rarely, if ever use. These and others created by 3rd parties will combine to give you the tools to do just anything you can think of once you're moving along as an iPhone developer. The Apple frameworks are separated into 4 layers: Cocoa Touch Layer, Media Layer, Core Services Layer and Core OS Layer. Within these layers, there are several frameworks each. The order of the Layers is top-down. Each layer uses functionality from the layer beneath it. If the functionality of one layer isn't sufficient, layers below may allow you to accomplish your required functionality. In this section, we'll look at the four layers and the frameworks within them.

The Cocoa Touch Layer is primarily the UI layer. Including the UIKit and Map Kit, the majority of the built-in widgets for your UI are in the Cocoa Touch layer (see table 1.1).

NOTE Cocoa Touch Layer (per Apple Docs) Implement a graphical, event-driven application in iPhone OS with the frameworks in the Cocoa Touch Layer. In addition, use the frameworks in this layer to access key device features, such as user contacts. Start your iPhone OS programming at this highest layer, and you'll automatically take advantage of lower level layers without getting into their details.

1.3 iPhone SDK Layers and Frameworks

1.3.1 Cocoa Touch Layer Frameworks

Please post comments or corrections to the Author Online forum: http://www.manning-sandbox.com/forum.jspa?forumID=

The Core Services Layer opens a lot of the functionality that's lower level and/or data intensive. Core Data is a great tool for building database functionality without delving into SQL or related technology. Similarly, the Address Book framework gains you access to the data of the device's Address Book. Core Location enables the app to determine the location of the device as needed. Core Foundation gives you URL/HTTP abilities.

Table 1.2 miPhone SDK Media Layer Framework Names and Descriptions

Audio Toolbox

This provides low-level audio recording, playback and manipulation. With this you can record a memo, for example.

Audio Unit This gives access to OS-supplied audio processing plug-ins. With this you can play, record and convert with various audio formats.

AV Foundation

This provides a streamlined audio recording and playback. With this you can configure audio sessions and respond to audio hardware callbacks.

Core Audio

This defines data types and constants used by other interfaces.

Core Graphics

This manages low-level 2D rendering including coordinate-space transformations and PDF documents.

Media Player

Provides facilities for navigating to and playing audio and video files. Use this to play user's audio and video on the device.

OpenGL ES

Provides compact subset of the OpenGL API for 2D and 3D including EAGL. Use this for gaming graphics.

Quartz Core

This is used for configuring animations and effects rendered including Core Animation. Use this for animation in your app.

1.3.3 Core Services Layer Frameworks

Please post comments or corrections to the Author Online forum: http://www.manning-sandbox.com/forum.jspa?forumID=

The Foundation framework gives you access to all types of data like date related objects, arrays, dictionaries, strings and many other classes you'll use repeatedly in just about any project. Store Kit allows you to implement in-app purchases for your app (see table 1.3).

NOTE Core Services Layer (per Apple Docs) Gain access to fundamental iPhone OS services with the frameworks in the Core Services layer. With these services, access files, low-level data types, Bonjour services, network sockets, and more. Use the frameworks in this layer if those in the Cocoa Touch and Media layers aren't sufficient for your needs. When you use the technologies at the Core Services layer, you'll automatically take advantage of the Core OS layer without getting into its details.

Please post comments or corrections to the Author Online forum: http://www.manning-sandbox.com/forum.jspa?forumID=

NOTE Core OS Layer (per Apple Docs) Manage the virtual memory system, threads, the file system, the network, and interprocess communication with the frameworks in the Core OS layer. This layer encompasses the kernel environment, drivers, and basic interfaces of iPhone OS. The drivers at this layer also provide the interface between the available hardware and the system frameworks that vend hardware features. Use the frameworks in this layer if those in the upper layers aren't sufficient for your needs.

Now that you know of the valuable components and resources in the SDK, let's look at one of the most valuable resources to an iPhone Developer.

The iPhone Developer Program provides you with a lot of reference information including examples, forums, videos and downloads. Most of your time will be spent developing and not thinking too much about the Developer Program except for day-to-day use of the forums, reference material and occasional download of a new version of the SDK. We'll spend more time really mastering the Program and Portal in the next chapter. However, let's look at the areas and concepts here so we have an overview understanding of it first. Since, for formal iPhone development, you'll need the Program and Portal, it makes sense to learn a bit more about it here before going further.

Table 1.4 miPhone SDK Core OS Layer Framework Names and Descriptions

CFNetwork access to network services and changes in configuration including HTTP, FtP and Bonjour

External Accessory

Provides communication with accessories connected to the device via cable or Bluetooth.

Security Secures data for an application when necessary.

System Provides BSD and POSIX functions.

1.4 The iPhone Developer Program and Portal

Please post comments or corrections to the Author Online forum: http://www.manning-sandbox.com/forum.jspa?forumID=

When you first visit the website for the developer program, you can be overwhelmed with information from videos to documents to sample code and more. I strongly encourage you to read, view, visit and download as much as you like, but don't feel obligated to do all of this. I'd recommend finishing the first three chapters of this book before diving too deep into the Developer Program website. Like with any skill, programming is best learned through practice. That's what makes the concepts solidify and become natural. Not to say you shouldn't read/view/etc. this material, but to some degree it can be confusing. This book intends to streamline a lot of this material. One document you should familiarize yourself with is the Human Interface G u i d e l i n e s ( t h e H I G ) : http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/ MobileHIG/Introduction/Introduction.html This document explains how the various Apple-provided widgets and interfaces in general are meant to be displayed and operate. It keeps the presentation and experience for the user consistent and intuitive. The same code is very useful when trying to understand certain aspects of a framework or how to do specific thing (e.g., play audio). You won't be able to access the forums until you're a member of the developer program. Once you can access the forums, you'll find them to be a very valuable resource.

Another important area of the Developer Program is the Portal. The Portal is where you manage your development configuration for your applications including certificates, provisioning profiles and application ids. Also, if your app requires push notifications or in-app purchase support, you manage that in the portal. Generally you'll need to use the Portal when you start a new project or need to make some changes to your provisioning profiles (e.g., add a new device id).

1.4.1 iPhone Developer Program

1.4.2 iPhone Development Program Portal

Please post comments or corrections to the Author Online forum: http://www.manning-sandbox.com/forum.jspa?forumID=