SlideShare une entreprise Scribd logo
1  sur  56
Effective Network
  Programming
   Techniques
     for Ios
  i P h o n e D e v C o n
     B o s t o n 2 0 1 1
Ben Scheirman

Director of Development
ChaiONE
Houston, TX


ben@scheirman.com
@subdigital
http://flux88.com
Why is this
         important?

99% of the apps we write are not self-
contained

Doing it wrong is terrible for the user’s
experience
Example 1:
The Stuttery Scroller
Example 1:
The Stuttery Scroller




             Accessing netw
                            ork on the
                  main thread
Example 2:
The Perpetual Loader
Example 2:
The Perpetual Loader



                             ...
                  oug h data
      cach ing en
Not
The Slow Loader
The Slow Loader




          Loading too mu
                        ch data...
Example 3:
Stale Toast
Example 3:
            Stale Toast


                     ow up
      ta do esn't sh
New da ht away...
      rig
What we’ll cover

ASIHTTPRequest

UITableView with
                      ProgressTracking
remote images
                      download/upload
                      progress
Leveraging HTTP
                      API Design Tips
Caching Patterns

Large File Transfer
ASI HTTP Request



http://github.com/pokeb/asihttprequest
Installation
Copy Files into your project

Copy Reachability

Link in Frameworks
Usage
Usage
#import “ASIHTTPRequest.h”
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setMethod:@”GET”];
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setMethod:@”GET”];
    [request setDelegate:self];
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setMethod:@”GET”];
    [request setDelegate:self];

  [request startAsynchronous];
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setMethod:@”GET”];
    [request setDelegate:self];

    [request startAsynchronous];
}
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setMethod:@”GET”];
    [request setDelegate:self];

    [request startAsynchronous];
}




- (void)requestDidComplete:(ASIHTTPRequest *)request {
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setMethod:@”GET”];
    [request setDelegate:self];

    [request startAsynchronous];
}




- (void)requestDidComplete:(ASIHTTPRequest *)request {
  //when requesting text (xml, json, etc)
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setMethod:@”GET”];
    [request setDelegate:self];

    [request startAsynchronous];
}




- (void)requestDidComplete:(ASIHTTPRequest *)request {
  //when requesting text (xml, json, etc)
    NSString *body = [request responseString];
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setMethod:@”GET”];
    [request setDelegate:self];

    [request startAsynchronous];
}




- (void)requestDidComplete:(ASIHTTPRequest *)request {
  //when requesting text (xml, json, etc)
    NSString *body = [request responseString];

    //when requesting binary data
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setMethod:@”GET”];
    [request setDelegate:self];

    [request startAsynchronous];
}




- (void)requestDidComplete:(ASIHTTPRequest *)request {
  //when requesting text (xml, json, etc)
    NSString *body = [request responseString];

    //when requesting binary data
    NSData *data = [request responseData];
Usage
#import “ASIHTTPRequest.h”

- (void)fetchCustomers {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setMethod:@”GET”];
    [request setDelegate:self];

    [request startAsynchronous];
}




- (void)requestDidComplete:(ASIHTTPRequest *)request {
  //when requesting text (xml, json, etc)
    NSString *body = [request responseString];

    //when requesting binary data
    NSData *data = [request responseData];
}
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
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
Caching


Fresh Data             User Experience
Caching


Fresh Data             User Experience
Caching
Cache Storage Policy


   Permanent


   Session


Cache Policy


   ASIAskServerIfModifiedWhenStaleCachePolicy


   ASIAskServerIfModifiedCachePolicy


   ASIOnlyLoadIfNotCachedCachePolicy


   ASIDontLoadCachePolicy


   ASIFallbackToCacheIfLoadFailsCachePolicy
Enabling the Cache

[ASIHTTPRequest setDownloadCache:[ASIDownloadCache sharedChache]];

//or per request
[request setDownloadCache:[ASIDownloadCache sharedCache]];
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!
    }
}
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
Uploading/
Downloading Large
      Files
Reduce memory overhead by streaming
directly to/from disk
Uploading/
Downloading Large
      Files
Reduce memory overhead by streaming
directly to/from disk

#import “ASIHTTPRequest.h”
Uploading/
Downloading Large
      Files
Reduce memory overhead by streaming
directly to/from disk

#import “ASIHTTPRequest.h”

- (void)fetchDatabase {
Uploading/
Downloading Large
      Files
Reduce memory overhead by streaming
directly to/from disk

#import “ASIHTTPRequest.h”

- (void)fetchDatabase {
    NSURL *url = [NSURL URLwithString:...];
Uploading/
Downloading Large
      Files
Reduce memory overhead by streaming
directly to/from disk

#import “ASIHTTPRequest.h”

- (void)fetchDatabase {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
Uploading/
Downloading Large
      Files
Reduce memory overhead by streaming
directly to/from disk

#import “ASIHTTPRequest.h”

- (void)fetchDatabase {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];
Uploading/
Downloading Large
      Files
Reduce memory overhead by streaming
directly to/from disk

#import “ASIHTTPRequest.h”

- (void)fetchDatabase {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];
    [request setDownloadDestinationPath:...];
Uploading/
Downloading Large
      Files
Reduce memory overhead by streaming
directly to/from disk

#import “ASIHTTPRequest.h”

- (void)fetchDatabase {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];
    [request setDownloadDestinationPath:...];

  [request startAsynchronous];
Uploading/
Downloading Large
      Files
Reduce memory overhead by streaming
directly to/from disk

#import “ASIHTTPRequest.h”

- (void)fetchDatabase {
    NSURL *url = [NSURL URLwithString:...];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];
    [request setDownloadDestinationPath:...];

    [request startAsynchronous];
}
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
API DESIGN TIPS
Don't couple your API to your internal server model
API DESIGN TIPS
Build in Versioning
API DESIGN TIPS
Record Client Device Info



                            Device Name
                            OS Version
                            App Version
API DESIGN TIPS
Provide News alerts

Enforce Minimum App Version

                              "Please update
                              to 1.2 for improved
                              functionality"
API DESIGN TIPS
Support E-Tags and/or If-Modified-Since
Header

Provide date & paging filters on large data
sets
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)
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)
Questions?

Contenu connexe

Tendances

async/await in Swift
async/await in Swiftasync/await in Swift
async/await in SwiftPeter Friese
 
Hd insight programming
Hd insight programmingHd insight programming
Hd insight programmingCasear Chu
 
Ufo Ship for AWS ECS
Ufo Ship for AWS ECSUfo Ship for AWS ECS
Ufo Ship for AWS ECSTung Nguyen
 
PuppetDB, Puppet Explorer and puppetdbquery
PuppetDB, Puppet Explorer and puppetdbqueryPuppetDB, Puppet Explorer and puppetdbquery
PuppetDB, Puppet Explorer and puppetdbqueryPuppet
 
REST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourREST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourCarl Brown
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensionserwanl
 
Intro to fog and openstack jp
Intro to fog and openstack jpIntro to fog and openstack jp
Intro to fog and openstack jpSatoshi Konno
 
Angular&node js upload file
Angular&node js upload fileAngular&node js upload file
Angular&node js upload fileHu Kenneth
 
Node collaboration - Exported Resources and PuppetDB
Node collaboration - Exported Resources and PuppetDBNode collaboration - Exported Resources and PuppetDB
Node collaboration - Exported Resources and PuppetDBm_richardson
 
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached georgepenkov
 
HTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranHTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranRobert Nyman
 
Apache CouchDB talk at Ontario GNU Linux Fest
Apache CouchDB talk at Ontario GNU Linux FestApache CouchDB talk at Ontario GNU Linux Fest
Apache CouchDB talk at Ontario GNU Linux FestMyles Braithwaite
 
Deploying E.L.K stack w Puppet
Deploying E.L.K stack w PuppetDeploying E.L.K stack w Puppet
Deploying E.L.K stack w PuppetColin Brown
 
Drupal 8 + Elasticsearch + Docker
Drupal 8 + Elasticsearch + DockerDrupal 8 + Elasticsearch + Docker
Drupal 8 + Elasticsearch + DockerRoald Umandal
 
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech TalkHacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech TalkRed Hat Developers
 
Programming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialProgramming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialJeff Smith
 

Tendances (20)

async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
 
Hd insight programming
Hd insight programmingHd insight programming
Hd insight programming
 
Ufo Ship for AWS ECS
Ufo Ship for AWS ECSUfo Ship for AWS ECS
Ufo Ship for AWS ECS
 
ABCD firebase
ABCD firebaseABCD firebase
ABCD firebase
 
PuppetDB, Puppet Explorer and puppetdbquery
PuppetDB, Puppet Explorer and puppetdbqueryPuppetDB, Puppet Explorer and puppetdbquery
PuppetDB, Puppet Explorer and puppetdbquery
 
Finding Clojure
Finding ClojureFinding Clojure
Finding Clojure
 
REST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourREST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A Tour
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
Intro to fog and openstack jp
Intro to fog and openstack jpIntro to fog and openstack jp
Intro to fog and openstack jp
 
Angular&node js upload file
Angular&node js upload fileAngular&node js upload file
Angular&node js upload file
 
Node collaboration - Exported Resources and PuppetDB
Node collaboration - Exported Resources and PuppetDBNode collaboration - Exported Resources and PuppetDB
Node collaboration - Exported Resources and PuppetDB
 
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
 
HTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - AltranHTML5 APIs - Where no man has gone before! - Altran
HTML5 APIs - Where no man has gone before! - Altran
 
Apache CouchDB talk at Ontario GNU Linux Fest
Apache CouchDB talk at Ontario GNU Linux FestApache CouchDB talk at Ontario GNU Linux Fest
Apache CouchDB talk at Ontario GNU Linux Fest
 
Dapper performance
Dapper performanceDapper performance
Dapper performance
 
Deploying E.L.K stack w Puppet
Deploying E.L.K stack w PuppetDeploying E.L.K stack w Puppet
Deploying E.L.K stack w Puppet
 
CouchDB Day NYC 2017: Replication
CouchDB Day NYC 2017: ReplicationCouchDB Day NYC 2017: Replication
CouchDB Day NYC 2017: Replication
 
Drupal 8 + Elasticsearch + Docker
Drupal 8 + Elasticsearch + DockerDrupal 8 + Elasticsearch + Docker
Drupal 8 + Elasticsearch + Docker
 
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech TalkHacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
 
Programming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialProgramming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorial
 

En vedette

En vedette (7)

Objective-C & iPhone for .NET Developers
Objective-C & iPhone for .NET DevelopersObjective-C & iPhone for .NET Developers
Objective-C & iPhone for .NET Developers
 
iPhone for .NET Developers
iPhone for .NET DevelopersiPhone for .NET Developers
iPhone for .NET Developers
 
Accessible Design
Accessible DesignAccessible Design
Accessible Design
 
Accessibility testing technology, human touch and value
Accessibility testing technology, human touch and value Accessibility testing technology, human touch and value
Accessibility testing technology, human touch and value
 
SQLite Techniques
SQLite TechniquesSQLite Techniques
SQLite Techniques
 
Meet Git
Meet GitMeet Git
Meet Git
 
StartUpSaturday_Deque
StartUpSaturday_DequeStartUpSaturday_Deque
StartUpSaturday_Deque
 

Similaire à Effective iOS Network Programming Techniques

Meetup uikit programming
Meetup uikit programmingMeetup uikit programming
Meetup uikit programmingjoaopmaia
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applicationslmrei
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCAWhymca
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexyananelson
 
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Sarp Erdag
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?Remy Sharp
 
Leveraging parse.com for Speedy Development
Leveraging parse.com for Speedy DevelopmentLeveraging parse.com for Speedy Development
Leveraging parse.com for Speedy DevelopmentAndrew Kozlik
 
Quick Fetch API Introduction
Quick Fetch API IntroductionQuick Fetch API Introduction
Quick Fetch API IntroductionChris Love
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdfShaiAlmog1
 
Lightning fast with Varnish
Lightning fast with VarnishLightning fast with Varnish
Lightning fast with VarnishVarnish Software
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxcelenarouzie
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4DEVCON
 
Efficient HTTP Apis
Efficient HTTP ApisEfficient HTTP Apis
Efficient HTTP ApisAdrian Cole
 
SQLite Techniques
SQLite TechniquesSQLite Techniques
SQLite Techniquesjoaopmaia
 
Saving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio HaroSaving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio HaroQuickBase, Inc.
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020Matt Raible
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsDylan Jay
 
HBaseCon 2015: Analyzing HBase Data with Apache Hive
HBaseCon 2015: Analyzing HBase Data with Apache  HiveHBaseCon 2015: Analyzing HBase Data with Apache  Hive
HBaseCon 2015: Analyzing HBase Data with Apache HiveHBaseCon
 

Similaire à Effective iOS Network Programming Techniques (20)

Meetup uikit programming
Meetup uikit programmingMeetup uikit programming
Meetup uikit programming
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applications
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCA
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexy
 
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
 
Leveraging parse.com for Speedy Development
Leveraging parse.com for Speedy DevelopmentLeveraging parse.com for Speedy Development
Leveraging parse.com for Speedy Development
 
Webscraping with asyncio
Webscraping with asyncioWebscraping with asyncio
Webscraping with asyncio
 
Quick Fetch API Introduction
Quick Fetch API IntroductionQuick Fetch API Introduction
Quick Fetch API Introduction
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
Lightning fast with Varnish
Lightning fast with VarnishLightning fast with Varnish
Lightning fast with Varnish
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
 
Moar tools for asynchrony!
Moar tools for asynchrony!Moar tools for asynchrony!
Moar tools for asynchrony!
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
 
Efficient HTTP Apis
Efficient HTTP ApisEfficient HTTP Apis
Efficient HTTP Apis
 
SQLite Techniques
SQLite TechniquesSQLite Techniques
SQLite Techniques
 
Saving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio HaroSaving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio Haro
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 
HBaseCon 2015: Analyzing HBase Data with Apache Hive
HBaseCon 2015: Analyzing HBase Data with Apache  HiveHBaseCon 2015: Analyzing HBase Data with Apache  Hive
HBaseCon 2015: Analyzing HBase Data with Apache Hive
 

Dernier

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Dernier (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

Effective iOS Network Programming Techniques

  • 1. Effective Network Programming Techniques for Ios i P h o n e D e v C o n B o s t o n 2 0 1 1
  • 2. Ben Scheirman Director of Development ChaiONE Houston, TX ben@scheirman.com @subdigital http://flux88.com
  • 3.
  • 4. Why is this important? 99% of the apps we write are not self- contained Doing it wrong is terrible for the user’s experience
  • 6. Example 1: The Stuttery Scroller Accessing netw ork on the main thread
  • 8. Example 2: The Perpetual Loader ... oug h data cach ing en Not
  • 10. The Slow Loader Loading too mu ch data...
  • 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
  • 15. Installation Copy Files into your project Copy Reachability Link in Frameworks
  • 16. Usage
  • 19. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...];
  • 20. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
  • 21. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setMethod:@”GET”];
  • 22. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setMethod:@”GET”]; [request setDelegate:self];
  • 23. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setMethod:@”GET”]; [request setDelegate:self]; [request startAsynchronous];
  • 24. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setMethod:@”GET”]; [request setDelegate:self]; [request startAsynchronous]; }
  • 25. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setMethod:@”GET”]; [request setDelegate:self]; [request startAsynchronous]; } - (void)requestDidComplete:(ASIHTTPRequest *)request {
  • 26. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setMethod:@”GET”]; [request setDelegate:self]; [request startAsynchronous]; } - (void)requestDidComplete:(ASIHTTPRequest *)request { //when requesting text (xml, json, etc)
  • 27. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setMethod:@”GET”]; [request setDelegate:self]; [request startAsynchronous]; } - (void)requestDidComplete:(ASIHTTPRequest *)request { //when requesting text (xml, json, etc) NSString *body = [request responseString];
  • 28. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setMethod:@”GET”]; [request setDelegate:self]; [request startAsynchronous]; } - (void)requestDidComplete:(ASIHTTPRequest *)request { //when requesting text (xml, json, etc) NSString *body = [request responseString]; //when requesting binary data
  • 29. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setMethod:@”GET”]; [request setDelegate:self]; [request startAsynchronous]; } - (void)requestDidComplete:(ASIHTTPRequest *)request { //when requesting text (xml, json, etc) NSString *body = [request responseString]; //when requesting binary data NSData *data = [request responseData];
  • 30. Usage #import “ASIHTTPRequest.h” - (void)fetchCustomers { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setMethod:@”GET”]; [request setDelegate:self]; [request startAsynchronous]; } - (void)requestDidComplete:(ASIHTTPRequest *)request { //when requesting text (xml, json, etc) NSString *body = [request responseString]; //when requesting binary data NSData *data = [request responseData]; }
  • 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
  • 33. Caching Fresh Data User Experience
  • 34. Caching Fresh Data User Experience
  • 35. Caching Cache Storage Policy Permanent Session Cache Policy ASIAskServerIfModifiedWhenStaleCachePolicy ASIAskServerIfModifiedCachePolicy ASIOnlyLoadIfNotCachedCachePolicy ASIDontLoadCachePolicy ASIFallbackToCacheIfLoadFailsCachePolicy
  • 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
  • 39. Uploading/ Downloading Large Files Reduce memory overhead by streaming directly to/from disk
  • 40. Uploading/ Downloading Large Files Reduce memory overhead by streaming directly to/from disk #import “ASIHTTPRequest.h”
  • 41. Uploading/ Downloading Large Files Reduce memory overhead by streaming directly to/from disk #import “ASIHTTPRequest.h” - (void)fetchDatabase {
  • 42. Uploading/ Downloading Large Files Reduce memory overhead by streaming directly to/from disk #import “ASIHTTPRequest.h” - (void)fetchDatabase { NSURL *url = [NSURL URLwithString:...];
  • 43. Uploading/ Downloading Large Files Reduce memory overhead by streaming directly to/from disk #import “ASIHTTPRequest.h” - (void)fetchDatabase { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
  • 44. Uploading/ Downloading Large Files Reduce memory overhead by streaming directly to/from disk #import “ASIHTTPRequest.h” - (void)fetchDatabase { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self];
  • 45. Uploading/ Downloading Large Files Reduce memory overhead by streaming directly to/from disk #import “ASIHTTPRequest.h” - (void)fetchDatabase { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request setDownloadDestinationPath:...];
  • 46. Uploading/ Downloading Large Files Reduce memory overhead by streaming directly to/from disk #import “ASIHTTPRequest.h” - (void)fetchDatabase { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request setDownloadDestinationPath:...]; [request startAsynchronous];
  • 47. Uploading/ Downloading Large Files Reduce memory overhead by streaming directly to/from disk #import “ASIHTTPRequest.h” - (void)fetchDatabase { NSURL *url = [NSURL URLwithString:...]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request setDownloadDestinationPath:...]; [request startAsynchronous]; }
  • 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
  • 49. API DESIGN TIPS Don't couple your API to your internal server model
  • 50. API DESIGN TIPS Build in Versioning
  • 51. API DESIGN TIPS Record Client Device Info Device Name OS Version App Version
  • 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)

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n