Advertisement
wkerswell

first

Oct 22nd, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  FirstViewController.h
  3. //  CPOP Test 4
  4. //
  5. //  Created by Will Kerswell on 22/10/2012.
  6. //  Copyright (c) 2012 Will Kerswell. All rights reserved.
  7. //
  8.  
  9. #import <UIKit/UIKit.h>
  10. #import "UIDevice+Resolutions.h"
  11. #import "TabBarViewController.h"
  12. #import "MapViewController.h"
  13. #import "DataBase.h"
  14. #import "GetJSON.h"
  15. #import <dispatch/dispatch.h>
  16.  
  17. @interface FirstViewController : UIViewController{
  18.     dispatch_queue_t queue;
  19. }
  20. @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *firstLoader;
  21. @property (weak, nonatomic) IBOutlet UILabel *downloadingLabel;
  22.  
  23. @end
  24.  
  25.  
  26. -------------
  27.  
  28.  
  29. //
  30. //  FirstViewController.m
  31. //  CPOP Test 4
  32. //
  33. //  Created by Will Kerswell on 22/10/2012.
  34. //  Copyright (c) 2012 Will Kerswell. All rights reserved.
  35. //
  36.  
  37. #import "FirstViewController.h"
  38.  
  39. @interface FirstViewController ()
  40.  
  41. @end
  42.  
  43. @implementation FirstViewController
  44. @synthesize firstLoader,downloadingLabel;
  45.  
  46.  
  47. /////////////////////////////
  48. #pragma mark - View lifecycle
  49. /////////////////////////////
  50.  
  51. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  52. {
  53.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  54.     if (self) {
  55.         // Custom initialization
  56.     }
  57.     return self;
  58. }
  59.  
  60. - (void)viewDidLoad
  61. {
  62.     //start the loader animation
  63.     [[self firstLoader]startAnimating];
  64.    
  65.     TabBarViewController *tab = [[TabBarViewController alloc]init];
  66.     [self presentViewController:tab animated:NO completion:nil];
  67.    
  68.    
  69.     //feilds for the poi db
  70.     NSArray *POIdbFields = [[NSArray alloc]initWithObjects:
  71.                             @"id",
  72.                             @"name",
  73.                             @"catID",
  74.                             @"description",
  75.                             @"lat" ,
  76.                             @"long" ,
  77.                             @"compLink" ,
  78.                             @"www" ,
  79.                             @"email" ,
  80.                             @"phone",
  81.                             @"status",
  82.                             @"retailer" ,
  83.                             @"sponsor",
  84.                             @"sponsorLevel" ,
  85.                             @"images",
  86.                             @"baner", nil];
  87.    
  88.     //feilds for cat db
  89.     NSArray *CatdbFields = [[NSArray alloc]initWithObjects:
  90.                             @"catID",
  91.                             @"name",
  92.                             @"pinImage",nil];
  93.    
  94.    
  95.     //create a new queue
  96.     queue = dispatch_queue_create("com.hazardousfrog.CPOPDataGet", NULL);
  97.    
  98.     //do all the database stuff in the back ground
  99.     dispatch_async(queue, ^{
  100.    
  101.         //create database
  102.         [self createDB];
  103.        
  104.         NSLog(@"JSON Start");
  105.        
  106.         //create an instance of that json objetc
  107.         GetJSON * JSON = [[GetJSON alloc] init];
  108.         //call the get json function and set it to an array
  109.         NSArray *JSONPOIArray = [[NSArray alloc]init];
  110.         NSArray *JSONCatArray = [[NSArray alloc]init];
  111.        
  112.         JSONPOIArray = [JSON getJSON:@"http://willkerswell.com/stuff/tests/testSponsor.php"];
  113.         JSONCatArray = [JSON getJSON:@"http://willkerswell.com/stuff/tests/testCat.php"];
  114.        
  115.         NSLog(@"JSON Finish");
  116.        
  117.         //create an instance of the database oject
  118.         DataBase * dataBase = [[DataBase alloc] init];
  119.        
  120.         //open the database connection
  121.         [dataBase openDB];
  122.        
  123.         //store the data
  124.         NSLog(@"Database Store Start");
  125.         [dataBase store:JSONPOIArray withFields:POIdbFields TableName:@"POI"];
  126.         [dataBase store:JSONCatArray withFields:CatdbFields TableName:@"categories"];
  127.         NSLog(@"Database Store Finish");
  128.        
  129.         NSLog(@"Database Get Start");
  130.         [dataBase getCatNames];
  131.         [dataBase getSponsors];
  132.         NSLog(@"Database Get Finish");
  133.        
  134.         sleep(3);
  135.        
  136.         dispatch_async(dispatch_get_main_queue(), ^{
  137.         //stop the loader once the database stuff has finished and get rid of the text
  138.         [[self firstLoader]stopAnimating];
  139.         self.downloadingLabel.text = @"";
  140.  
  141.  
  142.         });
  143.  
  144.    
  145.     });
  146.    
  147.  
  148.  
  149.    
  150.    
  151. //    [self performSegueWithIdentifier:@"first" sender:self];
  152. //    MapViewController *map = [[MapViewController alloc]init];
  153. //    [self presentViewController:map animated:YES completion:nil];
  154. //    [self pushMyNewViewController];
  155.    
  156.     [super viewDidLoad];
  157.     // Do any additional setup after loading the view.
  158. }
  159.  
  160. - (void)didReceiveMemoryWarning
  161. {
  162.     [super didReceiveMemoryWarning];
  163.     // Dispose of any resources that can be recreated.
  164. }
  165.  
  166.  
  167. /////////////////////////////
  168. #pragma mark - Database
  169. /////////////////////////////
  170.  
  171. -(void)createDB{
  172.     //make and array containing all the field types
  173.     NSArray *dbColumnsPOIs =[[NSArray alloc]initWithObjects:@"'id' TEXT PRIMARY KEY",
  174.                              @"'name' TEXT",
  175.                              @"'catID' TEXT",
  176.                              @"'description' TEXT",
  177.                              @"'lat' TEXT",
  178.                              @"'long' TEXT",
  179.                              @"'compLink' TEXT",
  180.                              @"'www' TEXT",
  181.                              @"'email' TEXT",
  182.                              @"'phone' TEXT",
  183.                              @"'status' TEXT",
  184.                              @"'retailer' TEXT",
  185.                              @"'sponsor'TEXT",
  186.                              @"'sponsorLevel' TEXT",
  187.                              @"'images'TEXT",
  188.                              @"'baner'TEXT", nil];
  189.    
  190.     //make and array containing all the field types
  191.     NSArray *dbColumnsCats =[[NSArray alloc]initWithObjects:
  192.                              
  193.                              @"'catID' TEXT PRIMARY KEY",
  194.                              @"'name' TEXT",
  195.                              @"'pinImage' TEXT",nil];
  196.    
  197.     //create an instance of the database oject
  198.     DataBase * dataBase = [[DataBase alloc] init];
  199.     //open the database connect
  200.     [dataBase openDB];
  201.     //create the table.
  202.     [dataBase createTable:@"POI" withFields:dbColumnsPOIs];
  203.     [dataBase createTable:@"categories" withFields:dbColumnsCats];
  204.    
  205.  
  206.  
  207.    
  208.    
  209. }
  210.  
  211.  
  212.  
  213.  
  214.  
  215. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement