iPhone in action: introduction to Web and SDK development

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

"The entry to the world of iPhone." -Aiden Montgomery, Wile Ltd.

"If you're new to iPhone development, this is your book!" -Larry C. Whipple, Mobile Productivity, Inc.

"Get this book. It's pure gold." -Martijn Dashorst, Author of Wicket in Action

"The quick & easy guide." -Premkumar Rajendran, HCL Technologies

"The only book on iPhone development I will ever need." -Rama Krishna Vavilala, Author of ASP.NET AJAX in Action

The iPhone explodes old ideas of a cell phone. Its native SDK offers a remarkable range of features including easy-to-build graphical objects, a unique navigation system, and a built-in database, all on a location-knowledgeable device. Websites and web apps can now behave like native iPhone apps, with great network integration.

iPhone in Action is an in-depth introduction to both native and web programming for the iPhone. You'll learn how to turn your web pages into compelling iPhone web apps using WebKit, iUI, and Canvas. The authors also take you step by step into more complex Objective-C programming. They help you master the iPhone SDK including its UI and features like accelerometers, GPS, the Address Book, SQLite, and many more. Using Apple's standard tools like Dashcode, Xcode, and Interface Builder, you'll learn how to best use both approaches: iPhone web and SDK programming. This book is intended as an introduction to its topics. Proficiency with C, Cocoa, or Objective-C is helpful but not required.

What's Inside

  • A comprehensive tutorial for iPhone programming
  • Web development, the SDK, and hybrid coding
  • Over 60 web, Dashcode, and SDK examples

Author(s): Christopher Allen, Shannon Appelcline
Edition: 1
Publisher: Manning Publications
Year: 2008

Language: English
Pages: 474

cover......Page 1
contents......Page 6
preface......Page 16
acknowledgments......Page 18
The audience......Page 20
Roadmap......Page 21
Software requirements......Page 23
About the cover illustration......Page 24
Introducing iPhone programming......Page 26
Introducing the iPhone......Page 28
1.1 iPhone core specifications......Page 29
1.1.1 iPhone input and output specifications......Page 30
1.1.2 iPhone network specifications......Page 31
1.1.3 iPhone browser specifications......Page 32
1.2 How the iPhone compares to the industry......Page 33
1.2.2 Competitive internet viewing......Page 34
1.3 How the iPhone is unique......Page 35
1.4.2 Output and orientations......Page 37
1.4.3 Input and iPhone mousing......Page 38
1.5 Summary......Page 40
2.1 Comparing the two programming styles......Page 41
2.2 A central philosophy: the continuum of programming......Page 43
2.3.1 Web development......Page 44
2.3.2 SDK development......Page 46
2.4 Stand-alone iPhone development......Page 47
2.4.1 Web development models......Page 48
2.4.2 SDK development models......Page 49
2.5 Integrated iPhone development......Page 50
2.5.2 Mixed development......Page 51
2.6 Summary......Page 52
Designing web pages for the iPhone......Page 54
Redeveloping web pages for the iPhone......Page 56
3.1 The iPhone viewport......Page 57
3.1.2 Making local viewport changes......Page 59
3.1.3 Viewport properties and constants......Page 60
3.2.1 Avoiding missing iPhone functionality......Page 61
3.2.3 Practicing good web work......Page 64
3.2.4 Fixing common problems......Page 66
3.3.1 Detecting the iPhone through USER_AGENT......Page 68
3.3.3 Optimizing with CSS......Page 69
3.4.1 The three bars......Page 70
3.4.2 Web clips......Page 71
3.5.1 One-fingered touches......Page 72
3.5.2 Two-fingered gestures......Page 73
3.6 Redisplaying web pages......Page 74
3.6.1 The Gmail iPhone pages......Page 75
3.6.2 The Facebook iPhone pages......Page 76
3.7 Supporting non-iPhone users......Page 77
3.8 Summary......Page 79
Advanced WebKit and textual web apps......Page 80
4.1 Introducing the WebKit......Page 81
4.1.2 New CSS elements......Page 82
4.2.1 The transform function......Page 84
4.2.2 The transition function......Page 86
4.2.3 The animation function......Page 89
4.3.2 Running a transaction......Page 90
4.3.3 A sample database......Page 91
4.5 Recognizing touches and gestures......Page 94
4.5.1 Accessing events......Page 95
4.5.2 Converting events......Page 96
4.5.3 Accessing touches......Page 97
4.5.4 Accessing gestures......Page 99
4.6 Recognizing orientation......Page 100
4.7.1 CSS gradients......Page 101
4.7.3 The Canvas alternative......Page 102
4.8 Summary......Page 103
Using iUI for web apps......Page 105
5.1.1 The graphical interface......Page 106
5.1.3 Other iPhone design elements......Page 108
5.2 Getting ready for iUI......Page 109
5.3 Developing with iUI......Page 110
5.3.1 The iUI toolbar......Page 111
5.3.2 iUI lists......Page 112
5.3.3 iUI dialogs......Page 114
5.3.4 iUI searches done right with Ajax......Page 115
5.3.5 iUI panels and rows......Page 116
5.3.6 iUI buttons......Page 117
5.3.7 iUI attributes......Page 118
5.4 Creating an iUI back end......Page 119
5.5.1 Organizing your code......Page 120
5.5.2 Improving data listings......Page 122
5.5.4 Selecting a different look......Page 123
5.6.1 Using jQuery with iUI......Page 124
5.6.2 Using iUI with WebKit......Page 125
5.7 Summary......Page 126
Using Canvas for web apps......Page 127
6.1.2 Ensuring compatibility......Page 128
6.1.3 Putting it together......Page 129
6.2 Drawing paths......Page 130
6.2.1 Basic path commands......Page 131
6.2.2 Curve commands......Page 132
6.3.2 Writing shape functions......Page 135
6.4.2 Gradient styles......Page 137
6.5 Modifying composition and clipping......Page 139
6.5.1 Global variables......Page 140
6.6.1 Transformations......Page 141
6.7 Incorporating images, patterns, and text......Page 142
6.7.1 Image commands......Page 143
6.7.3 Text commands......Page 144
6.8 Putting it together......Page 145
6.9 Applying animation......Page 146
6.10 Summary......Page 148
Building web apps with Dashcode......Page 149
7.1 An introduction to Dashcode......Page 150
7.1.2 The anatomy of Dashcode......Page 151
7.1.4 Deploying Dashcode projects......Page 155
7.2 Writing Dashcode programs......Page 156
7.2.1 Using library parts......Page 157
7.2.2 Adding action buttons......Page 159
7.2.3 Using the list-based Browser template......Page 160
7.2.4 Working with the stackLayout part......Page 161
7.2.5 Exploring the rest of Dashcode......Page 164
7.3.1 Integrating Dashcode with WebKit......Page 165
7.3.3 Integrating Dashcode with Canvas......Page 166
7.4 Summary......Page 167
8.1 Using Apache locally......Page 168
8.2.1 Using Safari......Page 169
8.2.2 Using Firefox......Page 171
8.2.3 Using the iPhone Simulator......Page 173
8.3 Debugging with your iPhone......Page 174
8.3.2 Using bookmarklets......Page 175
8.4 Profiling for the iPhone......Page 176
8.5 Summary......Page 177
SDK programming for web developers......Page 179
9.1 An introduction to C’s concepts......Page 180
9.1.1 Declarations and typing......Page 181
9.1.2 Memory management and pointers......Page 182
9.1.4 Compiling......Page 183
9.2 An introduction to object-oriented programming......Page 184
9.2.2 Messaging......Page 185
9.3 The Model-View-Controller (MVC) pattern......Page 186
9.4 Summary......Page 187
Learning SDK fundamentals......Page 190
Learning Objective-C and the iPhone OS......Page 192
10.1.1 Installing the SDK......Page 193
10.1.2 The anatomy of the SDK......Page 194
10.2.1 The big picture......Page 196
10.2.2 The message......Page 197
10.2.3 Class definition......Page 199
10.2.4 Properties......Page 201
10.2.5 Other compiler directives......Page 203
10.2.7 Wrapping up Objective-C......Page 204
10.3.1 The anatomy of the iPhone OS......Page 205
10.3.2 Windows and views......Page 208
10.4.1 Object creation......Page 209
10.4.2 Memory management......Page 211
10.4.3 Event response......Page 212
10.4.4 Life-cycle management......Page 213
10.5 Summary......Page 214
11.1 Introducing Xcode......Page 215
11.1.1 The anatomy of Xcode......Page 216
11.2 Creating a first project in Xcode: Hello, World!......Page 217
11.2.1 Understanding main.m......Page 218
11.2.2 Understanding the application delegate......Page 219
11.2.3 Writing Hello, World!......Page 221
11.3 Creating a new class in Xcode......Page 223
11.3.2 The header file......Page 224
11.3.3 The source code file......Page 225
11.4.1 Adding frameworks with Xcode......Page 227
11.4.2 Using alternate templates with Xcode......Page 228
11.4.3 Xcode tips and tricks......Page 229
11.5 Summary......Page 230
Using Interface Builder......Page 231
12.1.1 The anatomy of Interface Builder......Page 232
12.2.1 Creating new objects......Page 235
12.2.3 Using the inspector window......Page 236
12.2.4 Working with pictures......Page 238
12.3 Building connections in Interface Builder......Page 239
12.3.2 Connecting an object......Page 240
12.3.3 Coding with IBOutlets......Page 241
12.4.1 Building other connections......Page 242
12.4.3 Initializing Interface Builder objects......Page 243
12.4.5 Creating new .xib files......Page 244
12.5 Summary......Page 245
Creating basic view controllers......Page 246
13.1 The view controller family......Page 247
13.2.1 The anatomy of a view controller......Page 248
13.2.2 Creating a view controller......Page 249
13.2.3 Building up a view controller interface......Page 250
13.2.4 Using your view controller......Page 251
13.3.2 Creating a table view controller......Page 256
13.3.3 Building up a table interface......Page 258
13.3.4 Using your table view controller......Page 263
13.4 Summary......Page 264
14.1 An introduction to events......Page 265
14.1.1 The responder chain......Page 266
14.1.2 Touches and events......Page 267
14.2 A touching example: the event reporter......Page 269
14.2.1 Setting things up in Interface Builder......Page 270
14.2.2 Preparing a view for touches......Page 271
14.2.3 Controlling your events......Page 273
14.3.1 Regulating events......Page 275
14.3.2 Other event methods and properties......Page 276
14.4.2 Control events and actions......Page 277
14.4.3 The addTarget:action:forControlEvents: method......Page 279
14.5.1 Using addTarget:action:forControlEvents:......Page 280
14.5.2 Using an IBAction......Page 281
14.6.1 The UITextField......Page 282
14.6.2 The UISlider......Page 284
14.6.3 A TextField/Slider mashup......Page 285
14.6.5 Actions in use......Page 286
14.8 Summary......Page 287
Creating advanced view controllers......Page 289
15.1.1 The anatomy of a tab bar controller......Page 290
15.1.2 Creating a tab bar controller......Page 291
15.1.3 Building a tab bar interface......Page 292
15.2 The navigation controller......Page 296
15.2.1 The anatomy of a navigation controller......Page 297
15.2.2 Creating a navigation controller......Page 298
15.2.3 Building a navigation controller......Page 299
15.2.4 Using your navigation controller......Page 301
15.3 Using the flipside controller......Page 304
15.5 Summary......Page 306
Data: actions, preferences, files, SQLite, and addresses......Page 310
16.1 Accepting user actions......Page 311
16.2.1 Creating your own preferences......Page 313
16.2.2 Using the system settings......Page 318
16.3 Opening files......Page 322
16.3.1 Accessing your bundle......Page 323
16.3.2 Accessing other directories......Page 324
16.3.3 Manipulating files......Page 325
16.3.4 Filesaver: a UITextView example......Page 326
16.4 Using SQLite......Page 328
16.4.1 Setting up an SQLite database......Page 329
16.4.3 Accessing your SQLite database......Page 330
16.4.4 Building a navigation menu from a database......Page 331
16.5.1 An overview of the frameworks......Page 338
16.5.2 Accessing Address Book properties......Page 339
16.5.3 Querying the Address Book......Page 341
16.5.4 Using the Address Book UI......Page 343
16.6 Summary......Page 347
Programming with the SDK Toolkit......Page 308
Positioning: accelerometers and location......Page 349
17.1.2 The orientation notification......Page 350
17.2.1 Accessing the UIAccelerometer......Page 351
17.2.2 Parsing the UIAcceleration......Page 352
17.2.3 Checking for gravity......Page 353
17.2.5 Recognizing simple accelerometer movement......Page 355
17.3 The accelerometer and gestures......Page 358
17.4 All about Core Location......Page 360
17.4.1 The location classes......Page 361
17.4.2 An example using location and distance......Page 362
17.4.3 An example using altitude......Page 365
17.4.4 Core Location and the Internet......Page 367
17.5 Summary......Page 368
Media: images and sounds......Page 369
18.1.1 Loading a UIImage......Page 370
18.1.2 Drawing a UIImageView......Page 371
18.2 Drawing simple images with Core Graphics......Page 372
18.3.2 Taking photos......Page 374
18.3.3 Saving to the photo album......Page 375
18.4.1 The collage view controller......Page 376
18.4.2 The collage temporary image view......Page 379
18.4.3 The collage view......Page 380
18.4.4 Expanding on this example......Page 381
18.5.1 The media player class......Page 382
18.5.3 Better integrating the media player......Page 384
18.6 Playing sounds manually......Page 385
18.6.1 Playing simple sounds......Page 386
18.6.3 Playing complex sounds......Page 387
18.6.4 Other audio frameworks......Page 389
18.7 Summary......Page 390
Graphics: Quartz, Core Animation, and OpenGL......Page 391
19.2 The Quartz context......Page 392
19.2.1 Drawing to a UIView......Page 394
19.2.2 Drawing to a bitmap......Page 395
19.3 Drawing paths......Page 396
19.3.1 Finishing a path......Page 397
19.3.2 Creating reusable paths......Page 398
19.3.3 Drawing rectangles......Page 399
19.4.1 Setting colors......Page 400
19.4.2 Making transformations......Page 401
19.4.4 Other settings......Page 404
19.4.5 Managing the state......Page 405
19.5.1 Drawing gradients......Page 406
19.5.2 Drawing images......Page 408
19.5.3 Drawing words......Page 409
19.5.4 What we didn’t cover......Page 410
19.6.1 The photodraw view controller......Page 411
19.6.2 The photodraw view......Page 413
19.6.3 Expanding on the example......Page 415
19.7.1 The fundamentals of Core Animation......Page 416
19.7.3 Drawing a simple implicit animation......Page 417
19.7.4 Drawing a simple explicit animation......Page 418
19.9 Summary......Page 419
The web: web views and internet protocols......Page 421
20.2 Low-level networking......Page 422
20.2.1 The CFHost class......Page 423
20.3.1 Creating an NSURL......Page 424
20.3.3 Manipulating HTML data by hand......Page 425
20.4 Using UIWebView......Page 426
20.4.1 Calling up the web view......Page 427
20.4.3 Thumbnails: a web view example......Page 428
20.4.4 Google Maps: a Core Location example......Page 430
20.5 Parsing XML......Page 432
20.5.2 Acting as a delegate......Page 433
20.5.3 Building a sample RSS reader: an XML example......Page 434
20.5.4 Altitude redux: a Core Location example......Page 439
20.6.1 POSTing by hand......Page 441
20.6.2 Submitting forms......Page 442
20.7 Accessing the social web......Page 443
20.7.1 Using web protocols......Page 444
20.7.2 Using TouchJSON......Page 445
20.8 Summary......Page 446
A.1 UIKit framework classes......Page 448
A.2 Foundation framework classes......Page 450
A.3 Other classes......Page 451
B.2 Web app resources......Page 452
B.4 Other technologies......Page 453
C.2 Compiling to the iPhone......Page 454
C.3 Preparing for distribution via the iPhone App Store......Page 456
A......Page 458
C......Page 459
D......Page 461
F......Page 462
I......Page 463
M......Page 465
N......Page 466
P......Page 467
S......Page 468
T......Page 469
U......Page 470
W......Page 472
Z......Page 473
back cover......Page 474