Native iPhone Development 101
Sasmito Adibowo
adib (at) basil-salad dot com
http://www.basil-salad.com
3-Nov-2009
Agenda

Getting Started
What’s available to you
Accessing Web Services
Apple’s App Store
Beyond the App Store
Hello World Demo
What do you need
Minimum               Good to have
 An Intel Mac with     An iPhone or iPod
 Leopard or Snow       touch
 Leopard
                       iPhone Developer
 iPhone SDK (free      membership
 download)
                       A bank account
 Some free time and    (SWIFT)
 patience
The iPhone Stack


     Cocoa Touch                       WebKit

   Objective-C Runtime           Core*** Frameworks

 ANSI C Runtime     ANSI C++ Runtime        OpenGL ES

           Unix (BSD Variant), 32-bit ARM
Network Environment
Programming Languages
Objective-C
  Superset of C
  Dynamic Binding
  Cocoa Touch
C/C++
JavaScript
Class Declaration

#import <Foundation/Foundation.h>

@interface ThisIsAClass : NSObject {
@public
! // public data variables
@protected
! // protected data variables
@private
! // private data variables
!
}

// a message handler
-(void) doSomeThingAt:(id) whatever optionsAre:(NSDictionary*) options;

@end
Class Implementation

#import "ThisIsAClass.h"

@implementation ThisIsAClass

-(void) doSomeThingAt:(id) whatever optionsAre:(NSDictionary*) options
{
! if ([whatever respondsToSelector:@selector(sayHello:)]) {
! !   [whatever sayHello:options];
! }
}

@end
What you can do
Floating-point math          Network (TCP/IP) in & out
Threads                      Accelerated 3D graphics
C++ Programming              Memory-mapped files —
                             BSD mmap()
  STL included
                             Control iPod playback
Access the Address Book
                             (new in OS 3.0)
Compose e-mail
Write to the Photo Library
What you can’t do
Run in the background     Intercept phone calls /
                          SMSs / e-mails
Forking / multitasking
                          Create self-modifying
Access the Calendar
                          code
Read user’s e-mail
Access other
application’s data area
Cocoa Touch

MVC design pattern
Non-overlapping
window
Buttons, etc
Web Browser
Map Browser
Accessing Web Services

Built-in support
  JSON
  Property List Talk
3rd party
  SOAP
  RemObjects
JavaScript Object Notation (JSON)

                          {
                                  "firstName": "John",
 List of Values in                "lastName": "Smith",
                                  "address": {
 JavaScript syntax                    "streetAddress": "21 2nd Street",
                                       "city": "New York",
                                       "state": "NY",
 Useful if you have a                  "postalCode": "10021"
                                  },
 JavaScript interpreter           "phoneNumbers": [
 ready                              { "type": "home",
                                     "number": "212 555-1234" },
                                    { "type": "fax",
 iPhone has one!                  ]
                                      "number": "646 555-4567" }

                              }
JSON Example
 Your iApp             UIWebView         Your Server

             HTTP Request

                             JSON Response

             JSON String

             Data Values
Property List Talk
                                       <?xml version="1.0" encoding="UTF-8"?>
                                       <!DOCTYPE plist PUBLIC "-//Apple
                                       Computer//DTD PLIST 1.0//EN"
 Apple’s first-class XML                !       "http://www.apple.com/DTDs/
                                       PropertyList-1.0.dtd">
 format                                <plist version="1.0">
                                       <dict>
                                          <key>Year Of Birth</key>
                                          <integer>1965</integer>
 Can be easily                            <key>Pets Names</key>
                                          <array/>
 generated by a PHP                       <key>Picture</key>
                                          <data>

 script                                !       PEKBpYGlmYFCPA==
                                          </data>
                                          <key>City of Birth</key>
                                          <string>Springfield</string>
 Built-in conversion to                   <key>Name</key>
                                          <string>John Doe</string>
 Cocoa objects                            <key>Kids Names</key>
                                          <array>
                                       !       <string>John</string>
NSDictionary* dic = [NSDictionary      !       <string>Kyra</string>
   dictionaryWithContentsOfURL:...];      </array>
                                       </dict>
                                       </plist>
HTTP-Plist Example
Your iApp                NSDictionary                  Your Server

      [NSDictionary dictionaryWithContentsOfURL:...]


                                         HTTP Request


                                       Property List response

       new Dictionary object
Case Study: Fund Watch
  Display fund prices from
  Fundsupermart*
  Screen scraper
  JavaScript-based HTML
  parser
  Derived from
  Fundsupermart
  Dashboard Widget

*Fund Watch is not associated with Fundsupermart
Fund Watch Parser
Fund Watch               UIWebView          fundsupermart.com

    Load JavaScript library

                 Request fund prices page

                                     HTML Page

       Parse HTML Page

           Fund prices
The App Store
Accessible via iTunes
  3rd party screen
  scrapers
The only way to sell your
native apps
50K+ apps and counting
Requires a developer’s
account
Selling your Apps
1. Register for an iPhone Developer account

2. Get your bank’s SWIFT code

3. Prepare IRS documents

   1. Fill and submit SS-4 “Request for EIN” to IRS

   2. Wait for your EIN from IRS

   3. Fill form W8-BEN and submit to Apple

4. Fill the Paid Applications Contract

5. Register SWIFT code to Apple

6. Upload your paid applications to Apple’s iTunes Connect
Beyond the App Store

    Advertisement    Admob

         Analytics   Pinch Media

 Social Networking   OpenFeint
AdMob
Pinch Analytics
OpenFeint
Hello, World!
The End
http://basil-salad.com

Native Phone Development 101

  • 1.
    Native iPhone Development101 Sasmito Adibowo adib (at) basil-salad dot com http://www.basil-salad.com 3-Nov-2009
  • 2.
    Agenda Getting Started What’s availableto you Accessing Web Services Apple’s App Store Beyond the App Store Hello World Demo
  • 3.
    What do youneed Minimum Good to have An Intel Mac with An iPhone or iPod Leopard or Snow touch Leopard iPhone Developer iPhone SDK (free membership download) A bank account Some free time and (SWIFT) patience
  • 4.
    The iPhone Stack Cocoa Touch WebKit Objective-C Runtime Core*** Frameworks ANSI C Runtime ANSI C++ Runtime OpenGL ES Unix (BSD Variant), 32-bit ARM
  • 5.
  • 6.
    Programming Languages Objective-C Superset of C Dynamic Binding Cocoa Touch C/C++ JavaScript
  • 7.
    Class Declaration #import <Foundation/Foundation.h> @interfaceThisIsAClass : NSObject { @public ! // public data variables @protected ! // protected data variables @private ! // private data variables ! } // a message handler -(void) doSomeThingAt:(id) whatever optionsAre:(NSDictionary*) options; @end
  • 8.
    Class Implementation #import "ThisIsAClass.h" @implementationThisIsAClass -(void) doSomeThingAt:(id) whatever optionsAre:(NSDictionary*) options { ! if ([whatever respondsToSelector:@selector(sayHello:)]) { ! ! [whatever sayHello:options]; ! } } @end
  • 9.
    What you cando Floating-point math Network (TCP/IP) in & out Threads Accelerated 3D graphics C++ Programming Memory-mapped files — BSD mmap() STL included Control iPod playback Access the Address Book (new in OS 3.0) Compose e-mail Write to the Photo Library
  • 10.
    What you can’tdo Run in the background Intercept phone calls / SMSs / e-mails Forking / multitasking Create self-modifying Access the Calendar code Read user’s e-mail Access other application’s data area
  • 11.
    Cocoa Touch MVC designpattern Non-overlapping window Buttons, etc Web Browser Map Browser
  • 12.
    Accessing Web Services Built-insupport JSON Property List Talk 3rd party SOAP RemObjects
  • 13.
    JavaScript Object Notation(JSON) { "firstName": "John", List of Values in "lastName": "Smith", "address": { JavaScript syntax "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", Useful if you have a "postalCode": "10021" }, JavaScript interpreter "phoneNumbers": [ ready { "type": "home", "number": "212 555-1234" }, { "type": "fax", iPhone has one! ] "number": "646 555-4567" } }
  • 14.
    JSON Example YouriApp UIWebView Your Server HTTP Request JSON Response JSON String Data Values
  • 15.
    Property List Talk <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" Apple’s first-class XML ! "http://www.apple.com/DTDs/ PropertyList-1.0.dtd"> format <plist version="1.0"> <dict> <key>Year Of Birth</key> <integer>1965</integer> Can be easily <key>Pets Names</key> <array/> generated by a PHP <key>Picture</key> <data> script ! PEKBpYGlmYFCPA== </data> <key>City of Birth</key> <string>Springfield</string> Built-in conversion to <key>Name</key> <string>John Doe</string> Cocoa objects <key>Kids Names</key> <array> ! <string>John</string> NSDictionary* dic = [NSDictionary ! <string>Kyra</string> dictionaryWithContentsOfURL:...]; </array> </dict> </plist>
  • 16.
    HTTP-Plist Example Your iApp NSDictionary Your Server [NSDictionary dictionaryWithContentsOfURL:...] HTTP Request Property List response new Dictionary object
  • 17.
    Case Study: FundWatch Display fund prices from Fundsupermart* Screen scraper JavaScript-based HTML parser Derived from Fundsupermart Dashboard Widget *Fund Watch is not associated with Fundsupermart
  • 18.
    Fund Watch Parser FundWatch UIWebView fundsupermart.com Load JavaScript library Request fund prices page HTML Page Parse HTML Page Fund prices
  • 19.
    The App Store Accessiblevia iTunes 3rd party screen scrapers The only way to sell your native apps 50K+ apps and counting Requires a developer’s account
  • 20.
    Selling your Apps 1.Register for an iPhone Developer account 2. Get your bank’s SWIFT code 3. Prepare IRS documents 1. Fill and submit SS-4 “Request for EIN” to IRS 2. Wait for your EIN from IRS 3. Fill form W8-BEN and submit to Apple 4. Fill the Paid Applications Contract 5. Register SWIFT code to Apple 6. Upload your paid applications to Apple’s iTunes Connect
  • 21.
    Beyond the AppStore Advertisement Admob Analytics Pinch Media Social Networking OpenFeint
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.