Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // FirstViewController.m
- // CPOP Test 4
- //
- // Created by Will Kerswell on 22/10/2012.
- // Copyright (c) 2012 Will Kerswell. All rights reserved.
- //
- #import "FirstViewController.h"
- @interface FirstViewController ()
- @end
- @implementation FirstViewController
- @synthesize firstLoader,downloadingLabel;
- /////////////////////////////
- #pragma mark - View lifecycle
- /////////////////////////////
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- //start the loader animation
- [[self firstLoader]startAnimating];
- //feilds for the poi db
- NSArray *POIdbFields = [[NSArray alloc]initWithObjects:
- @"id",
- @"name",
- @"catID",
- @"description",
- @"lat" ,
- @"long" ,
- @"compLink" ,
- @"www" ,
- @"email" ,
- @"phone",
- @"status",
- @"retailer" ,
- @"sponsor",
- @"sponsorLevel" ,
- @"images",
- @"baner", nil];
- //feilds for cat db
- NSArray *CatdbFields = [[NSArray alloc]initWithObjects:
- @"catID",
- @"name",
- @"pinImage",nil];
- //create a new queue
- queue = dispatch_queue_create("com.hazardousfrog.CPOPDataGet", NULL);
- //do all the database stuff in the back ground
- dispatch_async(queue, ^{
- //create database
- [self createDB];
- NSLog(@"JSON Start");
- //create an instance of that json objetc
- GetJSON * JSON = [[GetJSON alloc] init];
- //call the get json function and set it to an array
- NSArray *JSONPOIArray = [[NSArray alloc]init];
- NSArray *JSONCatArray = [[NSArray alloc]init];
- JSONPOIArray = [JSON getJSON:@"http://willkerswell.com/stuff/tests/testSponsor.php"];
- JSONCatArray = [JSON getJSON:@"http://willkerswell.com/stuff/tests/testCat.php"];
- NSLog(@"JSON Finish");
- //create an instance of the database oject
- DataBase * dataBase = [[DataBase alloc] init];
- //open the database connection
- [dataBase openDB];
- //store the data
- NSLog(@"Database Store Start");
- NSLog(@"--Database Store POI");
- [dataBase store:JSONPOIArray withFields:POIdbFields TableName:@"POI"];
- NSLog(@"--Database Store Cats");
- [dataBase store:JSONCatArray withFields:CatdbFields TableName:@"categories"];
- NSLog(@"Database Store Finish");
- NSLog(@"Database Get Start");
- [dataBase getCatNames];
- [dataBase getSponsors];
- NSLog(@"Database Get Finish");
- sleep(2);
- dispatch_async(dispatch_get_main_queue(), ^{
- //stop the loader once the database stuff has finished and get rid of the text
- [[self firstLoader]stopAnimating];
- self.downloadingLabel.text = @"";
- });
- });
- dispatch_async(dispatch_get_main_queue(), ^{
- //once all the loading is done change view
- [self performSegueWithIdentifier:@"first" sender:self];
- });
- //can the view on the main queue. UIView related stuff is not fully thread safe
- //dispatch_sync(dispatch_get_main_queue(), ^{ [self performSegueWithIdentifier:@"first" sender:self];});
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- //-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
- // if ([[segue identifier] isEqualToString:@"first"]) {
- //
- // // Get destination view
- // TabBarViewController *vc = [segue destinationViewController];
- // NSMutableArray *array = [[NSMutableArray alloc]init ];
- // [array addObject:@"53.057801 "];
- // [array addObject:@"-2.68779504298 "];
- // [array addObject:@"0.011323 "];
- // [array addObject:@"0.027444 "];
- //
- // TabBarViewController.coord = array;
- // }
- //}
- /////////////////////////////
- #pragma mark - Database
- /////////////////////////////
- -(void)createDB{
- //make and array containing all the field types
- NSArray *dbColumnsPOIs =[[NSArray alloc]initWithObjects:@"'id' TEXT PRIMARY KEY",
- @"'name' TEXT",
- @"'catID' TEXT",
- @"'description' TEXT",
- @"'lat' TEXT",
- @"'long' TEXT",
- @"'compLink' TEXT",
- @"'www' TEXT",
- @"'email' TEXT",
- @"'phone' TEXT",
- @"'status' TEXT",
- @"'retailer' TEXT",
- @"'sponsor'TEXT",
- @"'sponsorLevel' TEXT",
- @"'images'TEXT",
- @"'baner'TEXT", nil];
- //make and array containing all the field types
- NSArray *dbColumnsCats =[[NSArray alloc]initWithObjects:
- @"'catID' TEXT PRIMARY KEY",
- @"'name' TEXT",
- @"'pinImage' TEXT",nil];
- //create an instance of the database oject
- DataBase * dataBase = [[DataBase alloc] init];
- //open the database connect
- [dataBase openDB];
- //create the table.
- [dataBase createTable:@"POI" withFields:dbColumnsPOIs];
- [dataBase createTable:@"categories" withFields:dbColumnsCats];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement