ios for errest - alternative version
TRANSCRIPT
![Page 1: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/1.jpg)
iOS REST ClientPaul Lynch@pauldlynch, [email protected]
![Page 2: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/2.jpg)
• Architecture of iOS apps
• Comet Architecture
• Model Implementation
• Controller Implementation
• Other iOS Concepts
iOS REST Client
![Page 3: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/3.jpg)
Architecture of iOS apps
• MVC - Model/View/Controller
• Objective C
• Foundation
• UIKit - UIApplication, UIViewController, UIView, UIControl
![Page 4: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/4.jpg)
Foundation
• NSArray, NSDictionary, NSSet
• NSValue
• NSPredicate
![Page 5: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/5.jpg)
UIKit - UIApplication
• UIApplication
• status bar
• window
• orientation
• AppDelegate
applicationDidFinishLaunchingWithOptions:
notifications - UIApplicationWillEnterForegroundNotification, UIApplicationDidEnterBackgroundNotification
![Page 6: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/6.jpg)
UIView
• animations
• gestures
![Page 7: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/7.jpg)
View Controllers
• - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
• navigationController, tabBarController
• rotation, transitions
• subclasses - e.g. UITableViewController
![Page 8: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/8.jpg)
Table Views
• UITableViewController
• UITableView
• data source
• delegate
• UITableViewCell
![Page 9: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/9.jpg)
Table view data source@protocol UITableViewDataSource<NSObject>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
...
@end
@interface NSIndexPath (UITableView)
+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
@property(nonatomic,readonly) NSInteger section;@property(nonatomic,readonly) NSInteger row;
@end
![Page 10: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/10.jpg)
Table view delegate@protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>
...- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;...- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;...@end
![Page 11: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/11.jpg)
Comet Architecture
![Page 12: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/12.jpg)
Comet Architecture
Marketing db
Reviews
WO dbXML
Linux, mySQL
Change Report
Mobile clients
![Page 13: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/13.jpg)
Comet Database
Features: skunum, runId; xml/json held as strings
Category
SKU
Review WC7SKU
Client
![Page 14: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/14.jpg)
REST API
• category - parent, children
• sku
• skudetail - contains full review and XML text
• brand - attribute of sku
![Page 15: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/15.jpg)
ERREST Routes routeRequestHandler.addRoute(new ERXRoute(Sku.ENTITY_NAME, "/sku", ERXRoute.Method.Options, SkuController.class, "options"));
routeRequestHandler.addRoute(new ERXRoute(Sku.ENTITY_NAME, "/sku", ERXRoute.Method.Head, SkuController.class, "head")); routeRequestHandler.addRoute(new ERXRoute(Sku.ENTITY_NAME, "/sku", ERXRoute.Method.All, SkuController.class, "index")); // MS: this only works with numeric ids routeRequestHandler.addRoute(new ERXRoute(Sku.ENTITY_NAME, "/sku/{action:identifier}", ERXRoute.Method.Get, SkuController.class)); routeRequestHandler.addRoute(new ERXRoute(Sku.ENTITY_NAME, "/sku/{sku:Sku}", ERXRoute.Method.Get, SkuController.class, "show")); routeRequestHandler.addRoute(new ERXRoute(Sku.ENTITY_NAME, "/sku/{sku:Sku}/{action:identifier}", ERXRoute.Method.All, SkuController.class));
plus Category, Brand, Skudetail
![Page 16: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/16.jpg)
Model Implementation
• PLRestful
• CometAPI
• Sku (etc)
![Page 17: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/17.jpg)
PLRestfultypedef void (^PLRestfulAPICompletionBlock)(PLRestful *api, id object, NSInteger 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;@property (nonatomic, assign) BOOL useBasicAuthentication;
+ (NSString *)messageForStatus:(NSInteger)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
![Page 18: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/18.jpg)
PLRestful - get- (void)get:(NSString *)requestString parameters:(NSDictionary *)parameters completionBlock:(PLRestfulAPICompletionBlock)completion {
NSURL *requestURL = [[NSURL URLWithString:endpoint] urlByAddingPath:requestString parameters:parameters]; NSLog(@"get: '%@'", [requestURL absoluteString]); NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL]; [request setHTTPMethod:@"GET"]; [self handleRequest:request completion:(PLRestfulAPICompletionBlock)completion];}
![Page 19: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/19.jpg)
PLRestful - post- (void)post:(NSString *)requestString content:(NSDictionary *)content completionBlock:(PLRestfulAPICompletionBlock)completion {
NSURL *requestURL = [[NSURL URLWithString:endpoint] urlByAddingPath:requestString parameters:nil]; NSLog(@"post: '%@'", [requestURL absoluteString]); NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL]; [request setHTTPMethod:@"POST"]; NSError *error = nil; request.HTTPBody = [NSJSONSerialization dataWithJSONObject:content options:0 error:&error]; if (error) { NSLog(@"json generation failed: %@", error); [self callCompletionBlockWithObject:nil status:0 error:[NSError errorWithDomain:@"com.plsys.semaphore.CometAPI" code:1003 userInfo:nil]]; return; } [self handleRequest:request completion:completion];}
![Page 20: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/20.jpg)
Controller Implementation
• SkuController
• subclass of UITableViewController
![Page 21: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/21.jpg)
SkuController - data source- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [skus count];}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *sku = [skus objectAtIndex:indexPath.row]; static NSString *CellIdentifier = @"SkuCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; } // Configure the cell... cell.textLabel.text = [[sku valueForKey:@"productName"] pl_stringByStrippingHTML]; cell.detailTextLabel.text = [sku valueForKey:@"skuNum"]; id image = [images objectAtIndex:indexPath.row]; if ([image isKindOfClass:[UIImage class]]) { cell.imageView.image = image; } return cell;}
![Page 22: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/22.jpg)
SkuController - tv delegate- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
NSDictionary *sku = [skus objectAtIndex:indexPath.row]; NSString *skuNum = [[sku valueForKey:@"skuNum"] copy]; NSLog(@"tapped: %@", skuNum); SkuDetail *view = [[SkuDetail alloc] initWithStyle:UITableViewStylePlain]; view.sku = sku; view.image = [images objectAtIndex:indexPath.row]; [self.navigationController pushViewController:view animated:YES];}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [self tableView:tableView accessoryButtonTappedForRowWithIndexPath:indexPath];}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == ((batch + 1)*25)-1) { // time to fetch more self.batch = ++batch; NSMutableDictionary *batchParameters = [parameters mutableCopy]; if (!batchParameters) batchParameters = [NSMutableDictionary dictionary]; [batchParameters setObject:[NSNumber numberWithInt:batch] forKey:@"batch"]; NSLog(@"batchParameters %@", batchParameters); [CometAPI get:query parameters:batchParameters completionBlock:^(PLRestful *api, id object, NSInteger status, NSError *error) { if (error) [self handleError:error]; else { [self didAddSkus:object]; } }]; }}
![Page 23: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/23.jpg)
Other iOS Topics
• Human Interface Guidelines
• Buttons - 44x44
• Gestures
• Controllers - mail, movie, picker
• Other UIControls - switch, slider, page control
• iOS 7
![Page 24: iOS for ERREST - alternative version](https://reader033.vdocuments.net/reader033/viewer/2022060108/554f59f2b4c905524c8b5428/html5/thumbnails/24.jpg)
Code Example
• SOE Status
• http://github.com/pauldlynch/SOEStatus
• older version, will update soon