Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // FirstViewController.h
- // CPOP Test 4
- //
- // Created by Will Kerswell on 22/10/2012.
- // Copyright (c) 2012 Will Kerswell. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #import "UIDevice+Resolutions.h"
- #import "TabBarViewController.h"
- #import "MapViewController.h"
- #import "DataBase.h"
- #import "GetJSON.h"
- #import <dispatch/dispatch.h>
- @interface FirstViewController : UIViewController{
- dispatch_queue_t queue;
- }
- @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *firstLoader;
- @property (weak, nonatomic) IBOutlet UILabel *downloadingLabel;
- @end
- -------------
- //
- // 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];
- TabBarViewController *tab = [[TabBarViewController alloc]init];
- [self presentViewController:tab animated:NO completion:nil];
- //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");
- [dataBase store:JSONPOIArray withFields:POIdbFields TableName:@"POI"];
- [dataBase store:JSONCatArray withFields:CatdbFields TableName:@"categories"];
- NSLog(@"Database Store Finish");
- NSLog(@"Database Get Start");
- [dataBase getCatNames];
- [dataBase getSponsors];
- NSLog(@"Database Get Finish");
- sleep(3);
- 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 = @"";
- });
- });
- // [self performSegueWithIdentifier:@"first" sender:self];
- // MapViewController *map = [[MapViewController alloc]init];
- // [self presentViewController:map animated:YES completion:nil];
- // [self pushMyNewViewController];
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /////////////////////////////
- #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