iPhone Development For Experienced Web Developers

Preview:

Citation preview

iPhone Development for Experienced Web Developers

SXSW 2009

Poll

How many people here have tried native iPhone app development?

Poll

How many people here have an online application that might use an iPhone client?

Session Overview

• Web developer POV• What’s different about iPhone dev• Our project, some design decisions• Code review and mini-tutorial

What’s Different

Web Developers… are mad for POWER

iPhone Processor• ~400mhz processor,

128mb RAM• 10 to 100 times

slower processor and memory

• Premature optimization takes on a different meaning

* http://www.primatelabs.ca/blog/2007/08/geekbench-2-for-the-iphone/

Web Latency

Web Latency

Web Latency

Web Latency

Web Latency

iPhone Latency

Latency Management

• Take latency into account during app design• Asynchronous operations where anything

takes any kind of time• Explicitly define wait indicators• Multithreaded considerations

Tools

• Must have an Intel powered Mac• $99 to join Apple Developer Program• Free SDK download, Xcode, Objective C, Cocoa• http://developer.apple.com

TIOBE Programming Community Index

TIOBE Programming Community Index

Objective C

• C with OO added• Totally different than typical Web Languages– Pointers– Memory Management

• No garbage collection– Non-linear code execution– Syntactical… saltiness?

• Language features seem years behind• Biggest burden to new non-Mac developers

Xcode

Cocoa

• Objective C all low level• Cocoa is really great

Coming Soon

Our Project

CP Screenshot

Protocols

• https for secure data transfer• Username and password authenticated• REST web services interface• JSON for returning data

Web Services SOAP (google)<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP-ENV:Header> <developer_email xsi:type="xsd:string" SOAP-ENC:root="1">INSERT_DEVELOPER_EMAIL_HERE</developer_email> <display_locale xsi:type="xsd:string" SOAP-ENC:root="1">en_US</display_locale> <developer_password xsi:type="xsd:string" SOAP-ENC:root="1">INSERT_PASSWORD_HERE</developer_password></SOAP-ENV:Header><SOAP-ENV:Body> <ns1:associateAccount xmlns:ns1="http://www.google.com/api/adsense/v3" SOAP-ENC:root="1"> <loginEmail>INSERT_PUBLISHER_EMAIL_HERE</loginEmail> <postalCode>12345</postalCode> <phone xsi:nil="1"/> <developerUrl>INSERT_DEVELOPER_URL_HERE</developerUrl> </ns1:associateAccount></SOAP-ENV:Body></SOAP-ENV:Envelope>

Web Services REST (amazon)http://rcm.amazon.com/e/cm?t=[Associates ID goes here]&l=st1&search=[subject keyword goes here]&mode=[product line goes here]&p=102&o=1&f=xml

Web Services

• Lightweight approach for mobile is critical• REST interfaces far more efficient• JSON for returned data– Allows you to serialize objects with known data and

types– Can be 100x faster to parse than XML– Significantly fewer control characters and other

overhead– Platform independent, easy to consume– http://www.json.org

Architecture Diagram

Auth

Provide List of Websites

Provide Data for Website

Local Storage

Retrieve List of Projects

Retrieve Data for Project

Edit/Enter Username and

Password

Web

https; GET websites

JSON result, [[name,id]…]

https; GET websites?id=

JSON result, [[key,value]…]

App Demo and Mini-Tutorial

Concepts

• MVC• Events and Delegates• Interface Builder

Lay of the Land

• AppDelegate– (initialization)

• ViewController– (one per page) • + XIB

• Data Models

Pseudocode

Screen loads• Controller asks model for data• Make http request• Parse JSON (convert it to objects)• Display data• Wait for additional events (e.g. button click):

repeat process with new page

Pseudocode

Screen loadsController asks model for data• Make http request• Parse JSON (convert it to objects)• Display data• Wait for additional events (e.g. button click):

repeat process with new page

Pseudocode

Screen loadsController asks model for dataMake http request• Parse JSON (convert it to objects)• Display data• Wait for additional events (e.g. button click):

repeat process with new page

Pseudocode

Screen loadsController asks model for dataMake http requestParse JSON (convert it to objects)• Display data• Wait for additional events (e.g. button click):

repeat process with new page

Pseudocode

Screen loadsController asks model for dataMake http requestParse JSON (convert it to objects)Display data• Wait for additional events (e.g. button click):

repeat process with new page

Pseudocode

Screen loadsController asks model for dataMake http requestParse JSON (convert it to objects)Display dataWait for additional events (e.g. button click):

repeat process with new page

Memory Management

• Golden Rule– If you alloc/init it, you have to release it.• If you’re returning it from a method, autorelease it.

– If you’re NOT alloc/init’ing it, do NOT release it!• Mostly…

• Finding leaks– Use “Instruments” application.

Compiling, Testing, Distributing

• Apple developer account required to deploy to iPhone

• Simulator can be different than actual device operation, be sure to QA thoroughly

• Be prepared for a lengthy process of registering, signing, deploying and obtaining approval for your app

What We Think

Really Like about iPhone Development

• Incomparable/exciting platform• Standardized hardware, relatively powerful

device• Cocoa and MVC paradigm• “Bare metal” programming is a refreshing

change of pace

Really Don’t’ Like

• Objective C, iPhone application model– Lots of assumed knowledge and undocumented rules to

discover– Refactoring is difficult

• Xcode– Code editor with GCC config… have come to expect more

• App deployment• Flaky connectivity• Apple controlled domain

Q & A

Recommended