ios 移动应用通用逻辑流程

来源:互联网 发布:key查看器软件 编辑:程序博客网 时间:2024/05/16 14:09

请先看前一篇文章<移动互联网app业务逻辑图>,以便于理解

http://blog.csdn.net/uxyheaven/article/details/14156659


1 start

[objc] view plaincopy在CODE上查看代码片派生到我的代码片
  1. - (IBAction)clickStart:(id)sender {  
  2.     for (int i = 0; i < 6; i++) {  
  3.         UILabel *label = (UILabel *)[self.view viewWithTag:i + 10000];  
  4.         label.textColor = [UIColor blueColor];  
  5.     }  
  6.       
  7.     [self performSelector:@selector(start) withObject:nil afterDelay:1];  
  8. }  

2 发送请求

[objc] view plaincopy在CODE上查看代码片派生到我的代码片
  1. -(void) httpGET{  
  2.     UILabel *label = (UILabel *)[self.view viewWithTag:1 + 10000];  
  3.     label.textColor = [UIColor redColor];  
  4.     __block id myself =self;  
  5.     HttpRequest *request = [self.entityModel.requestHelper get:@"api/nodes.json"];  
  6.     [request succeed:^(HttpRequest *op) {  
  7.         UILabel *label = (UILabel *)[self.view viewWithTag:2 + 10000];  
  8.         label.textColor = [UIColor redColor];  
  9.           
  10.         if([op isCachedResponse]) {  
  11.             NSLog(@"Data from cache %@", [op responseString]);  
  12.             [myself parseData:[op responseString] isCachedResponse:YES];  
  13.         }  
  14.         else {  
  15.             NSLog(@"Data from server %@", [op responseString]);  
  16.             [myself parseData:[op responseString] isCachedResponse:NO];  
  17.         }  
  18.     } failed:^(HttpRequest *op, NSError *err) {  
  19.         NSString *str = [NSString stringWithFormat:@"Request error : %@", [err localizedDescription]];  
  20.         NSLogD(@"%@", str);  
  21.           
  22.         // SHOWMBProgressHUD(@"Message", str, nil, NO, 3);  
  23.         [self loadFromDBProcess];  
  24.     }];  
  25.       
  26.     [self.entityModel.requestHelper submit:request];  
  27. }  

3 解析请求

[objc] view plaincopy在CODE上查看代码片派生到我的代码片
  1. -(void) parseData:(NSString *)str isCachedResponse:(BOOL)isCachedResponse{  
  2.     UILabel *label = (UILabel *)[self.view viewWithTag:3 + 10000];  
  3.     label.textColor = [UIColor redColor];  
  4.       
  5.     self.model = [str toModels:[RubyChinaNodeEntity class]];  
  6.       
  7.     [self performSelector:@selector(refreshUI) withObject:nil afterDelay:1];  
  8.       
  9.     if (isCachedResponse) {  
  10.         ;  
  11.     }else{  
  12.         [self performSelector:@selector(saveToDBProcess) withObject:nil afterDelay:1];  
  13.     }  
  14. }  

4 持久化

[objc] view plaincopy在CODE上查看代码片派生到我的代码片
  1. -(void) saveToDBProcess{  
  2.     UILabel *label = (UILabel *)[self.view viewWithTag:4 + 10000];  
  3.     label.textColor = [UIColor redColor];  
  4.     PERF_ENTER_( saveAllToDB )  
  5.     [self.model saveAllToDB];  
  6.     PERF_LEAVE_( saveAllToDB )  
  7. }  

5 刷新UI

[objc] view plaincopy在CODE上查看代码片派生到我的代码片
  1. -(void) refreshUI{  
  2.     UILabel *label = (UILabel *)[self.view viewWithTag:5 + 10000];  
  3.     label.textColor = [UIColor redColor];  
  4.       
  5.     if (self.model && self.model.count > 0) {  
  6.         NSString *str = [[self.model objectAtIndex:0] YYJSONString];  
  7.         SHOWMBProgressHUD(@"Data", str, nilNO3);  
  8.     }  
  9. }  

6 读取数据库

[objc] view plaincopy在CODE上查看代码片派生到我的代码片
  1. -(void) loadFromDBProcess{  
  2.     self.model = [NSArray loadFromDBWithClass:[RubyChinaNodeEntity class]];  
  3.       
  4.     [self performSelector:@selector(refreshUI) withObject:nil afterDelay:1];  
  5. }  

具体代码请在

https://github.com/uxyheaven/XYQuickDevelop

BusinessVC中查看

0 0
原创粉丝点击