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

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Dernier (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

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