Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this


  1. 1. iOS for ERRESTPaul
  2. 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, etciOS for ERREST
  3. 3. App Store• Huddle• b-london• iWycombe• SOE Status• Comet• Mobile Adventure Walks
  4. 4. Enterprise• DeLaRue• Oetker• Dorchester• LifeFitness• BidPresentation x 5
  5. 5. WebObjects• Powerful system for server based development• ERREST for RESTful servers• Historically has used browsers for clients
  6. 6. Problem?
  7. 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. 8. The Client• iOS• iPhone for mass distribution• iPad for Enterprise• Objective C• Xcode• Foundation, UIKit
  9. 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. 10. Objective C• ARC• properties• blocks• Grand Central Dispatch• Xcode• git• OSS
  11. 11. • Huddle• SaaS,Windows/IE oriented• Comet *• High street large enterprise, high volume shopping, ERREST• Walks *• “exergaming”, ERREST,Amazon EC2• SOE Status• game server updatesExamples
  12. 12. Comet ArchitectureMarketingdbReviewsWO dbXMLLinux, mySQLChangeReportMobileclients
  13. 13. Comet DatabaseFeatures: skunum, runId; xml/json held as stringsCategorySKUReview WC7SKUClient
  14. 14. REST API• category - parent, children• sku• skudetail - contains full review and XML text• brand - attribute of sku
  15. 15. Code Approaches• CometAPI subclasses PLRestful• per entity subclass (Sku, Category, etc)• NSURLConnection• ASIHTTPRequest (not maintained)• AFNetworking (github)• RESTKit -
  16. 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. 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. 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. 19. CometAPI get...self.completionBlock = completion;[[UIApplication sharedApplication] prp_pushNetworkActivity];self.restQueue = [[NSOperationQueue alloc] init]; = @"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. 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. 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, [[[parametersobjectForKey:key] description] stringByAddingPercentEscapesUsingEncoding:kCFStringEncodingUTF8]]];first = NO;}}return [NSURL URLWithString:requestString];}
  22. 22. Traps• Connection reliability• isn’t really “always on”• Data cacheing• performance?• capacity?• Update cacheing• Reachability
  23. 23. Write more apps!
  24. 24. Q&APaul