SlideShare a Scribd company logo
iOS for ERREST
Paul Lynch
@pauldlynch
paul@plsys.co.uk
• We know WebObjects & ERREST
• The client problem
• Example ERREST/iOS architecture
• Some code specifics
• Some iOS client-server tips
• NOT how to write an iOS app - NO UITableView, etc
iOS for ERREST
App Store
• Huddle
• b-london
• iWycombe
• SOE Status
• Comet
• Mobile Adventure Walks
Enterprise
• DeLaRue
• Oetker
• Dorchester
• LifeFitness
• BidPresentation x 5
WebObjects
• Powerful system for server based development
• ERREST for RESTful servers
• Historically has used browsers for clients
Problem?
The Client
• HTML
• BUT <table>, Browser Wars, CSS
• Java Client
• BUT - Java - in the client
• Javascript/Single Page Applications
• BUT Javascript?, what framework?
The Client
• iOS
• iPhone for mass distribution
• iPad for Enterprise
• Objective C
• Xcode
• Foundation, UIKit
iOS Statistics (WWDC 2013)
• 600 million units sold
• iPad has 82% tablet market share
• iOS 6 is on 93% of all iOS devices
Objective C
• ARC
• properties
• blocks
• Grand Central Dispatch
• Xcode
• git
• OSS
• Huddle
• SaaS,Windows/IE oriented
• Comet *
• High street large enterprise, high volume shopping, ERREST
• Walks *
• “exergaming”, ERREST,Amazon EC2
• SOE Status
• game server updates
Examples
Comet Architecture
Marketing
db
Reviews
WO db
XML
Linux, mySQL
Change
Report
Mobile
clients
Comet Database
Features: skunum, runId; xml/json held as strings
Category
SKU
Review WC7SKU
Client
REST API
• category - parent, children
• sku
• skudetail - contains full review and XML text
• brand - attribute of sku
Code Approaches
• CometAPI subclasses PLRestful
• per entity subclass (Sku, Category, etc)
• NSURLConnection
• ASIHTTPRequest (not maintained)
• AFNetworking (github)
• RESTKit - RestKit.org
PLRestful.h
@class PLRestful;
typedef void (^PLRestfulAPICompletionBlock)(PLRestful *api, id object, int status, NSError *error);
@interface PLRestful : NSObject
@property (nonatomic, copy) NSString *endpoint;
@property (nonatomic, copy) PLRestfulAPICompletionBlock completionBlock;
@property (nonatomic, copy) NSString *username;
@property (nonatomic, copy) NSString *password;
+ (NSString *)messageForStatus:(int)status;
+ (BOOL)checkReachability:(NSURL *)url;
+ (void)get:(NSString *)requestPath parameters:(NSDictionary *)parameters completionBlock:(PLRestfulAPICompletionBlock)completion;
+ (void)post:(NSString *)requestPath content:(NSDictionary *)content completionBlock:(PLRestfulAPICompletionBlock)completion;
- (void)get:(NSString *)requestPath parameters:(NSDictionary *)parameters completionBlock:(PLRestfulAPICompletionBlock)completion;
- (void)post:(NSString *)requestPath content:(NSDictionary *)content completionBlock:(PLRestfulAPICompletionBlock)completion;
@end
[skudetail viewDidLoad];
NSString *query = [NSString stringWithFormat:@"skudetail/%@.json", [sku valueForKey:@"skuNum"]];
[CometAPI get:query parameters:nil completionBlock:^(CometAPI *api, id object, int status, NSError *error) {
if (error) {
[PRPAlertView showWithTitle:@"Error" message:@"Unable to fetch product details" buttonTitle:@"Continue"];
} else {
self.sku = object;
[self.tableView reloadData];
}
}];
CometAPI get
- (void)get:(NSString *)requestString parameters:(NSDictionary *)parameters completionBlock:(CometAPICompletionBlock)completion {
NSURL *requestURL = [[NSURL URLWithString:endpoint] urlByAddingPath:requestString andParameters:parameters];
NSLog(@"get: '%@'", [requestURL absoluteString]);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL];
if (userName && password && useBasicAuthentication) {
NSString *authString = [[NSString stringWithFormat:@"%@:%@", userName, password] base64];
NSString *authHeader = [NSString stringWithFormat:@"Basic %@", authString];
[request setValue:authHeader forHTTPHeaderField:@"Authorization"];! !
}
//[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
! [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
...
CometAPI get
...
self.completionBlock = completion;
[[UIApplication sharedApplication] prp_pushNetworkActivity];
self.restQueue = [[NSOperationQueue alloc] init];
self.restQueue.name = @"Comet REST Queue";
[NSURLConnection sendAsynchronousRequest:request queue:self.restQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
if (error) {
NSLog(@"%s %@", __PRETTY_FUNCTION__, error);
[self callCompletionBlockWithObject:nil error:error];
} else {
if ([data length] == 0) {
NSLog(@"no data");
[self callCompletionBlockWithObject:nil error:[NSError errorWithDomain:@"com.plsys.semaphore.CometAPI" code:1001 userInfo:nil]];
} else {
NSError *error;
id object = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
if (object) {
[self callCompletionBlockWithObject:object error:nil];
} else {
NSLog(@"received bad json: (%d) '%@'", [data length], [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
[self callCompletionBlockWithObject:nil error:[NSError errorWithDomain:@"com.plsys.semaphore.CometAPI" code:1002 userInfo:nil]];
}
}
}
}];
}
CometAPI Methods
- (void)callCompletionBlockWithObject:(id)object error:(NSError *)error {
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] prp_popNetworkActivity];
self.completionBlock(self, object, error);
});
}
CometAPI Methods
- (NSURL *)urlByAddingPath:(NSString *)path andParameters:(NSDictionary *)parameters; {
NSString *requestString = [[self absoluteString] stringByAppendingPathComponent:path];
if (parameters) {
requestString = [requestString stringByAppendingString:@"?"];
BOOL first = YES;
for (NSString *key in [parameters allKeys]) {
if (!first) {
requestString = [requestString stringByAppendingString:@"&"];
}
requestString = [requestString stringByAppendingString:[NSString stringWithFormat:@"%@=%@", key, [[[parameters
objectForKey:key] description] stringByAddingPercentEscapesUsingEncoding:kCFStringEncodingUTF8]]];
first = NO;
}
}
return [NSURL URLWithString:requestString];
}
Traps
• Connection reliability
• isn’t really “always on”
• Data cacheing
• performance?
• capacity?
• Update cacheing
• Reachability
Write more apps!
Q&A
Paul Lynch
paul@plsys.co.uk
@pauldlynch

More Related Content

PDF
Getting Started with Riak - NoSQL Live 2010 - Boston
Rusty Klophaus
 
PDF
State of Search, Solr and Facets in Drupal 8 - Drupalcamp Belgium 2015
Dropsolid
 
PPTX
Jekyll, static websites generator
Francesco Napoletano
 
PDF
Jekyll Presentation Slides
Curtis Miller
 
ODP
Introduction to blogging with Jekyll
Eric Lathrop
 
PDF
State of search | drupal dinner
Joris Vercammen
 
PDF
Omeka: Open Archives and Exhibits for Anyone
Jeremy Boggs
 
PDF
State of search | drupalcamp ghent
Joris Vercammen
 
Getting Started with Riak - NoSQL Live 2010 - Boston
Rusty Klophaus
 
State of Search, Solr and Facets in Drupal 8 - Drupalcamp Belgium 2015
Dropsolid
 
Jekyll, static websites generator
Francesco Napoletano
 
Jekyll Presentation Slides
Curtis Miller
 
Introduction to blogging with Jekyll
Eric Lathrop
 
State of search | drupal dinner
Joris Vercammen
 
Omeka: Open Archives and Exhibits for Anyone
Jeremy Boggs
 
State of search | drupalcamp ghent
Joris Vercammen
 

What's hot (20)

PDF
Riding rails for 10 years
jduff
 
PPTX
In-browser storage and me
Jason Casden
 
KEY
Rails with mongodb
Kosuke Matsuda
 
PPTX
SharePoint 2013 APIs
John Calvert
 
PPTX
2011 NetUG HH: ASP.NET MVC & HTML 5
Daniel Fisher
 
PDF
Build Reusable Web Components using HTML5 Web cComponents
Gil Fink
 
PDF
0323社内LT大会
Akira Ohta
 
PDF
How and When to Use FalcorJS
Wiredcraft
 
PDF
State of search | drupalcon dublin
Joris Vercammen
 
PDF
.NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA...
Christian Nagel
 
PDF
A Persistence Service for the OSGi Framework - Carl Rosenberger, Chief Softwa...
mfrancis
 
KEY
Impression of Rails 3
Kosuke Matsuda
 
PPTX
Web Ninja
Alfi Rizka
 
PDF
Web components
Gil Fink
 
PDF
PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Petra Barus
 
PPTX
Panada: An Introduction by Iskandar Soesman
k4ndar
 
KEY
HTML5 History & Features
Dave Ross
 
PPTX
Neos CMS and SEO
Sebastian Helzle
 
PPTX
Service stack all the things
cyberzeddk
 
PPTX
PowerShell Basics for Office Apps and Servers
Greg McMurray
 
Riding rails for 10 years
jduff
 
In-browser storage and me
Jason Casden
 
Rails with mongodb
Kosuke Matsuda
 
SharePoint 2013 APIs
John Calvert
 
2011 NetUG HH: ASP.NET MVC & HTML 5
Daniel Fisher
 
Build Reusable Web Components using HTML5 Web cComponents
Gil Fink
 
0323社内LT大会
Akira Ohta
 
How and When to Use FalcorJS
Wiredcraft
 
State of search | drupalcon dublin
Joris Vercammen
 
.NET Core Foundations - Dependency Injection, Logging & Configuration - BASTA...
Christian Nagel
 
A Persistence Service for the OSGi Framework - Carl Rosenberger, Chief Softwa...
mfrancis
 
Impression of Rails 3
Kosuke Matsuda
 
Web Ninja
Alfi Rizka
 
Web components
Gil Fink
 
PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
Petra Barus
 
Panada: An Introduction by Iskandar Soesman
k4ndar
 
HTML5 History & Features
Dave Ross
 
Neos CMS and SEO
Sebastian Helzle
 
Service stack all the things
cyberzeddk
 
PowerShell Basics for Office Apps and Servers
Greg McMurray
 
Ad

Viewers also liked (18)

PDF
Life outside WO
WO Community
 
PDF
WOver
WO Community
 
PDF
Apache Cayenne for WO Devs
WO Community
 
PDF
Migrating existing Projects to Wonder
WO Community
 
PDF
Advanced Apache Cayenne
WO Community
 
PDF
Using Nagios to monitor your WO systems
WO Community
 
PDF
iOS for ERREST - alternative version
WO Community
 
PDF
Build and deployment
WO Community
 
PDF
D2W Stateful Controllers
WO Community
 
PDF
Filtering data with D2W
WO Community
 
PDF
Reenabling SOAP using ERJaxWS
WO Community
 
PDF
Unit Testing with WOUnit
WO Community
 
PDF
Chaining the Beast - Testing Wonder Applications in the Real World
WO Community
 
PDF
KAAccessControl
WO Community
 
PDF
High availability
WO Community
 
PDF
Deploying WO on Windows
WO Community
 
PDF
"Framework Principal" pattern
WO Community
 
PDF
In memory OLAP engine
WO Community
 
Life outside WO
WO Community
 
Apache Cayenne for WO Devs
WO Community
 
Migrating existing Projects to Wonder
WO Community
 
Advanced Apache Cayenne
WO Community
 
Using Nagios to monitor your WO systems
WO Community
 
iOS for ERREST - alternative version
WO Community
 
Build and deployment
WO Community
 
D2W Stateful Controllers
WO Community
 
Filtering data with D2W
WO Community
 
Reenabling SOAP using ERJaxWS
WO Community
 
Unit Testing with WOUnit
WO Community
 
Chaining the Beast - Testing Wonder Applications in the Real World
WO Community
 
KAAccessControl
WO Community
 
High availability
WO Community
 
Deploying WO on Windows
WO Community
 
"Framework Principal" pattern
WO Community
 
In memory OLAP engine
WO Community
 
Ad

Similar to iOS for ERREST (20)

PDF
Webエンジニアから見たiOS5
Satoshi Asano
 
PDF
Icinga 2009 at OSMC
Icinga
 
PPTX
Crafting Evolvable Api Responses
darrelmiller71
 
PDF
Afstuderen bij Sogeti Java
erwindeg
 
PPTX
SharePoint and jQuery Essentials
Mark Rackley
 
KEY
Android lessons you won't learn in school
Michael Galpin
 
PDF
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
ITGinGer
 
PDF
スマートフォンサイトの作成術 - 大川洋一
okyawa
 
PPTX
Building RESTfull Data Services with WebAPI
Gert Drapers
 
PDF
Rails and iOS with RestKit
Andrew Culver
 
PPTX
Full Stack Development with Node.js and NoSQL
All Things Open
 
PPTX
Full stack development with node and NoSQL - All Things Open - October 2017
Matthew Groves
 
PDF
Developing iOS REST Applications
lmrei
 
PPTX
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
Sébastien Levert
 
PPTX
Untangling the web10
Derek Jacoby
 
PDF
e10sとアプリ間通信
Makoto Kato
 
PDF
Painless Persistence in a Disconnected World
Christian Melchior
 
PDF
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
confluent
 
PPTX
Untangling - fall2017 - week 9
Derek Jacoby
 
PDF
Stencil the time for vanilla web components has arrived
Gil Fink
 
Webエンジニアから見たiOS5
Satoshi Asano
 
Icinga 2009 at OSMC
Icinga
 
Crafting Evolvable Api Responses
darrelmiller71
 
Afstuderen bij Sogeti Java
erwindeg
 
SharePoint and jQuery Essentials
Mark Rackley
 
Android lessons you won't learn in school
Michael Galpin
 
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
ITGinGer
 
スマートフォンサイトの作成術 - 大川洋一
okyawa
 
Building RESTfull Data Services with WebAPI
Gert Drapers
 
Rails and iOS with RestKit
Andrew Culver
 
Full Stack Development with Node.js and NoSQL
All Things Open
 
Full stack development with node and NoSQL - All Things Open - October 2017
Matthew Groves
 
Developing iOS REST Applications
lmrei
 
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
Sébastien Levert
 
Untangling the web10
Derek Jacoby
 
e10sとアプリ間通信
Makoto Kato
 
Painless Persistence in a Disconnected World
Christian Melchior
 
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
confluent
 
Untangling - fall2017 - week 9
Derek Jacoby
 
Stencil the time for vanilla web components has arrived
Gil Fink
 

More from WO Community (12)

PDF
Localizing your apps for multibyte languages
WO Community
 
PDF
WOdka
WO Community
 
PDF
ERGroupware
WO Community
 
PDF
D2W Branding Using jQuery ThemeRoller
WO Community
 
PDF
CMS / BLOG and SnoWOman
WO Community
 
PDF
Using GIT
WO Community
 
PDF
Persistent Session Storage
WO Community
 
PDF
Back2 future
WO Community
 
PDF
WebObjects Optimization
WO Community
 
PDF
Dynamic Elements
WO Community
 
PDF
Practical ERSync
WO Community
 
PDF
ERRest: the Basics
WO Community
 
Localizing your apps for multibyte languages
WO Community
 
ERGroupware
WO Community
 
D2W Branding Using jQuery ThemeRoller
WO Community
 
CMS / BLOG and SnoWOman
WO Community
 
Using GIT
WO Community
 
Persistent Session Storage
WO Community
 
Back2 future
WO Community
 
WebObjects Optimization
WO Community
 
Dynamic Elements
WO Community
 
Practical ERSync
WO Community
 
ERRest: the Basics
WO Community
 

Recently uploaded (20)

PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Doc9.....................................
SofiaCollazos
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 

iOS for ERREST

  • 2. • We know WebObjects & ERREST • The client problem • Example ERREST/iOS architecture • Some code specifics • Some iOS client-server tips • NOT how to write an iOS app - NO UITableView, etc iOS for ERREST
  • 3. App Store • Huddle • b-london • iWycombe • SOE Status • Comet • Mobile Adventure Walks
  • 4. Enterprise • DeLaRue • Oetker • Dorchester • LifeFitness • BidPresentation x 5
  • 5. WebObjects • Powerful system for server based development • ERREST for RESTful servers • Historically has used browsers for clients
  • 7. The Client • HTML • BUT <table>, Browser Wars, CSS • Java Client • BUT - Java - in the client • Javascript/Single Page Applications • BUT Javascript?, what framework?
  • 8. The Client • iOS • iPhone for mass distribution • iPad for Enterprise • Objective C • Xcode • Foundation, UIKit
  • 9. iOS Statistics (WWDC 2013) • 600 million units sold • iPad has 82% tablet market share • iOS 6 is on 93% of all iOS devices
  • 10. Objective C • ARC • properties • blocks • Grand Central Dispatch • Xcode • git • OSS
  • 11. • Huddle • SaaS,Windows/IE oriented • Comet * • High street large enterprise, high volume shopping, ERREST • Walks * • “exergaming”, ERREST,Amazon EC2 • SOE Status • game server updates Examples
  • 12. Comet Architecture Marketing db Reviews WO db XML Linux, mySQL Change Report Mobile clients
  • 13. Comet Database Features: skunum, runId; xml/json held as strings Category SKU Review WC7SKU Client
  • 14. REST API • category - parent, children • sku • skudetail - contains full review and XML text • brand - attribute of sku
  • 15. Code Approaches • CometAPI subclasses PLRestful • per entity subclass (Sku, Category, etc) • NSURLConnection • ASIHTTPRequest (not maintained) • AFNetworking (github) • RESTKit - RestKit.org
  • 16. PLRestful.h @class PLRestful; typedef void (^PLRestfulAPICompletionBlock)(PLRestful *api, id object, int status, NSError *error); @interface PLRestful : NSObject @property (nonatomic, copy) NSString *endpoint; @property (nonatomic, copy) PLRestfulAPICompletionBlock completionBlock; @property (nonatomic, copy) NSString *username; @property (nonatomic, copy) NSString *password; + (NSString *)messageForStatus:(int)status; + (BOOL)checkReachability:(NSURL *)url; + (void)get:(NSString *)requestPath parameters:(NSDictionary *)parameters completionBlock:(PLRestfulAPICompletionBlock)completion; + (void)post:(NSString *)requestPath content:(NSDictionary *)content completionBlock:(PLRestfulAPICompletionBlock)completion; - (void)get:(NSString *)requestPath parameters:(NSDictionary *)parameters completionBlock:(PLRestfulAPICompletionBlock)completion; - (void)post:(NSString *)requestPath content:(NSDictionary *)content completionBlock:(PLRestfulAPICompletionBlock)completion; @end
  • 17. [skudetail viewDidLoad]; NSString *query = [NSString stringWithFormat:@"skudetail/%@.json", [sku valueForKey:@"skuNum"]]; [CometAPI get:query parameters:nil completionBlock:^(CometAPI *api, id object, int status, NSError *error) { if (error) { [PRPAlertView showWithTitle:@"Error" message:@"Unable to fetch product details" buttonTitle:@"Continue"]; } else { self.sku = object; [self.tableView reloadData]; } }];
  • 18. CometAPI get - (void)get:(NSString *)requestString parameters:(NSDictionary *)parameters completionBlock:(CometAPICompletionBlock)completion { NSURL *requestURL = [[NSURL URLWithString:endpoint] urlByAddingPath:requestString andParameters:parameters]; NSLog(@"get: '%@'", [requestURL absoluteString]); NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL]; if (userName && password && useBasicAuthentication) { NSString *authString = [[NSString stringWithFormat:@"%@:%@", userName, password] base64]; NSString *authHeader = [NSString stringWithFormat:@"Basic %@", authString]; [request setValue:authHeader forHTTPHeaderField:@"Authorization"];! ! } //[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; ! [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; ...
  • 19. CometAPI get ... self.completionBlock = completion; [[UIApplication sharedApplication] prp_pushNetworkActivity]; self.restQueue = [[NSOperationQueue alloc] init]; self.restQueue.name = @"Comet REST Queue"; [NSURLConnection sendAsynchronousRequest:request queue:self.restQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){ if (error) { NSLog(@"%s %@", __PRETTY_FUNCTION__, error); [self callCompletionBlockWithObject:nil error:error]; } else { if ([data length] == 0) { NSLog(@"no data"); [self callCompletionBlockWithObject:nil error:[NSError errorWithDomain:@"com.plsys.semaphore.CometAPI" code:1001 userInfo:nil]]; } else { NSError *error; id object = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; if (object) { [self callCompletionBlockWithObject:object error:nil]; } else { NSLog(@"received bad json: (%d) '%@'", [data length], [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); [self callCompletionBlockWithObject:nil error:[NSError errorWithDomain:@"com.plsys.semaphore.CometAPI" code:1002 userInfo:nil]]; } } } }]; }
  • 20. CometAPI Methods - (void)callCompletionBlockWithObject:(id)object error:(NSError *)error { dispatch_async(dispatch_get_main_queue(), ^{ [[UIApplication sharedApplication] prp_popNetworkActivity]; self.completionBlock(self, object, error); }); }
  • 21. CometAPI Methods - (NSURL *)urlByAddingPath:(NSString *)path andParameters:(NSDictionary *)parameters; { NSString *requestString = [[self absoluteString] stringByAppendingPathComponent:path]; if (parameters) { requestString = [requestString stringByAppendingString:@"?"]; BOOL first = YES; for (NSString *key in [parameters allKeys]) { if (!first) { requestString = [requestString stringByAppendingString:@"&"]; } requestString = [requestString stringByAppendingString:[NSString stringWithFormat:@"%@=%@", key, [[[parameters objectForKey:key] description] stringByAddingPercentEscapesUsingEncoding:kCFStringEncodingUTF8]]]; first = NO; } } return [NSURL URLWithString:requestString]; }
  • 22. Traps • Connection reliability • isn’t really “always on” • Data cacheing • performance? • capacity? • Update cacheing • Reachability