I gave this talk at iPhone Dev Con in Boston, April 2011. It covers making HTTP requests using ASIHTTPRequest, UITableViews with remote images, caching patterns, and API design tips.
12. Example 3:
Stale Toast
ow up
ta do esn't sh
New da ht away...
rig
13. What we’ll cover
ASIHTTPRequest
UITableView with
ProgressTracking
remote images
download/upload
progress
Leveraging HTTP
API Design Tips
Caching Patterns
Large File Transfer
31. UITableView
Loading images for each row
Don't make blocking network calls in
tableView:cellForRowAtIndexPath:
Leverage NSOperationQueue & a local cache
Fetch images in the background, reload the row
in question
32. Leveraging HTTP
Request Response
200 OK
GET /resource
{resource:"hello"}
GET /resource
304 NOT MODIFIED
If-Modified-Since: 03-16-2010 16:10:00
200 OK
E-Tag: 000ea9512912
GET /resource
{resource:"hello"}
GET /resource
304 NOT MODIFIED
If-None-Match: 000ea9512912
36. Enabling the Cache
[ASIHTTPRequest setDownloadCache:[ASIDownloadCache sharedChache]];
//or per request
[request setDownloadCache:[ASIDownloadCache sharedCache]];
37. Checking if Content
exists in the cache
#import "ASIHTTPRequest.h"
#import "ASIDownloadCache.h"
- (void)fetchImage {
NSURL *url = ...
NSData *cacheData = [[ASIDownloadCache sharedCache]
cachedDataForUrl:url];
//do something with cachedData
}
#import "ASIHTTPRequest.h"
#import "ASIDownloadCache.h"
- (void)requestDidFinish(ASIHTTPRequest *)request {
if ([request didUseCachedResponse]) {
//response was served from the cache!
}
}
38. Tracking Progress
Set the upload/download progress delegate of
a request
smart enough to bind directly to a
UIProgressView
For large downloads, turn on
showAccurateProgress in order to get better
precision over progress updates
48. Tracking progress
of multiple requests
ASINetworkQueue
requests are NSOperations, just add them
need to explicitly start the queue
will perform a HEAD request for each to
calculate total size
reports progress similar to ASIHTTPRequest
52. API DESIGN TIPS
Provide News alerts
Enforce Minimum App Version
"Please update
to 1.2 for improved
functionality"
53. API DESIGN TIPS
Support E-Tags and/or If-Modified-Since
Header
Provide date & paging filters on large data
sets
54. API DESIGN TIPS
Techniques for permeating deletes
Client supplies list of ids, server returns list
of valid ones
Client requests changes, server returns a set
of new records, changed records, and
deleted record ids (requires server to
support soft-delete of archive tables)
55. API DESIGN TIPS
Aggressively cache (where possible) public
endpoints
Avoid caching per-user information unless
you have a limited set of users (or unlimited
memory on your server)