afnetworking

23
AFNetworking Houston iPhone Developers Meetup October 25th, 2011

Upload: joaopmaia

Post on 31-Aug-2014

8.465 views

Category:

Technology


2 download

DESCRIPTION

AFNetworking slides from my presentation at the October 2011 meeting of the Houston iPhone Developers Meetup.

TRANSCRIPT

Page 1: AFNetworking

AFNetworking

Houston iPhone Developers MeetupOctober 25th, 2011

Page 2: AFNetworking

•Full time contract iOS developer out of The Woodlands

•Contact me at http://ipanemalabs.com

•Founder of Houston iPhone Developers Meetup

•Organizer of Houston PHP Users Group

•Personal iPhone apps on store since 2008

•Personal site at http://pessoal.org

2

AFNetworking

Who?

Page 3: AFNetworking

•Overview of what AFNetworking provides

•Background on the project

•Alternatives to it

•Bunch of code examples

•Feel free to ask questions

3

AFNetworking

Tonight’s session

Page 4: AFNetworking

•Open-source library shared by Gowalla

•Available at https://github.com/gowalla/AFNetworking

•Created in the development of Gowalla for iPhone

•Inspired by an Apple sample project (MVC Networking)

•Uses Objective-C blocks for everything (requires iOS 4+)

•MIT license

4

AFNetworking

Background

Page 5: AFNetworking

•Main authors very active behind the project

•Mattt Thompson - http://mattt.me

•Scott Raymond - http://scottraymond.net

5

AFNetworking

More background

Page 6: AFNetworking

•ASIHTTPRequest

•Convenience wrapper with lots of useful features

•Author decided to stop maintaining it

•NSURLConnection

•Lots of tedious / boilerplate code to manage HTTP requests

•Other options

•RestKit - http://restkit.org

•SVHTTPRequest - http://github.com/samvermette/SVHTTPRequest

6

AFNetworking

Alternatives

Page 7: AFNetworking

•Uses NSOperation for scheduling and concurrency

•Blocks for request completion / failure callbacks

•Convenience features:

•Requests for JSON, XML, Image data, etc

•File upload with progress callback

•API client request

7

AFNetworking

AFNetworking features

Page 8: AFNetworking

•Clone AFNetworking github project

•Copy “AFNetworking” sub-folder to your own Xcode project

•Clone JSONKit github project

•https://github.com/johnezang/JSONKit

•Copy JSONKit.h and JSONKit.m to your own Xcode project

8

AFNetworking

Installation

Page 9: AFNetworking

•Provides appledoc compatible documentation

•Appledoc available at https://github.com/tomaz/appledoc

•git clone https://github.com/tomaz/appledoc.git

•sudo sh install-appledoc.sh

•Installs on /usr/local/bin

•git clone https://github.com/gowalla/AFNetworking.git

•cd AFNetworking

•appledoc -p AFNetworking -c "Gowalla" --company-id com.gowalla

AFNetworking/*.h

9

AFNetworking

Great documentation

Page 10: AFNetworking

10

AFNetworking

Documentation

Page 11: AFNetworking

•Closures for Objective-C

•Similar in nature to JavaScript closures, but slightly different

•Great for callback-centric code

•Available since iOS 4

•Used a lot in Grand Central Dispatch (GCD)

•Great introduction documentation available from Apple

•http://developer.apple.com/library/ios/#documentation/cocoa/

Conceptual/Blocks/Articles/00_Introduction.html

11

AFNetworking

Blocks

Page 12: AFNetworking

12

AFNetworking

Blocks

Page 13: AFNetworking

•Library core is AFURLConnectionOperation

•NSOperation subclass to make asynchronous requests

•Subclasses

•AFJSONRequestOperation – JSON requests

•AFXMLRequestOperation – XML requests

•AFPropertyListRequestOperation – Plist requests

•AFImageRequestOperation – Image requests

13

AFNetworking

Core classes

Page 14: AFNetworking

14

AFNetworking

JSON request

•Dependency on JSONKit

•Very high performance JSON library

•Benchmark results available at https://github.com/johnezang/JSONKit

•Claimed to be faster than parsing/serializing binary plists.

•Results contested by TouchJSON author

Page 15: AFNetworking

15

AFNetworking

JSON request

Page 16: AFNetworking

•Similar to JSON request, but no automatic parsing of payload

•Block callback allows you to kick off the XML parsing

16

AFNetworking

XML request

Page 17: AFNetworking

17

AFNetworking

XML request

Page 18: AFNetworking

•Load remote images on UIImageView asynchronously

•Alternative to EGOImageView and similar libraries

•Great on table view cells, async requests get canceled as cells are re-used

•Simple interface to load images

•-[UIImageView setImageWithURL:placeholderImage:]

•More control available through a different method

18

AFNetworking

Image request

Page 19: AFNetworking

19

AFNetworking

Image request

Page 20: AFNetworking

•AFHTTPClient at the core

•Detects appropriate operation for each request

•AFGowallaAPIClient subclass of that

•Easy to extend core class with the business logic for your own web service

implementation

20

AFNetworking

API request

Page 21: AFNetworking

21

AFNetworking

AFGowallaAPIClient

Page 22: AFNetworking

•AFNetworking post on Gowalla’s Engineering blog

•http://engineering.gowalla.com/2011/10/24/afnetworking/

•Github pages

•Great information on issue list, network graph

•Mattt’s profile page - https://github.com/mattt/

•TTTAttributedLabel - https://github.com/mattt/TTTAttributedLabel

•FormatterKit - https://github.com/mattt/FormatterKit

22

AFNetworking

More information

Page 23: AFNetworking

Contact: