Skip to content

Instantly share code, notes, and snippets.

@pachun
Created July 17, 2012 16:32
hello
//
// ViewController.m
// ColorTest
//
// Created by Paul Marano on 7/13/12.
// Copyright (c) 2012 Cogent Technologies, Inc. All rights reserved.
//
#import "ViewController.h"
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
#import "SBJSON.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize textView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setTextView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)dealloc {
[textView release];
[super dealloc];
}
- (IBAction)showColors:(UIButton *) sender {
// Get device unique ID
UIDevice *device = [UIDevice currentDevice];
NSString *uniqueIdentifier = [device uniqueIdentifier];
// Start request
//NSString *code = textField.text;
//NSURL *url = [NSURL URLWithString:@"http://www.pjmarano.com/promos/"];
NSURL *url = [NSURL URLWithString:@"http://cogentmacmini/index.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
//[request setPostValue:@"1" forKey:@"rw_app_id"];
//[request setPostValue:code forKey:@"code"];
//[request setPostValue:uniqueIdentifier forKey:@"device_id"];
[request setDelegate:self];
[request startAsynchronous];
// Hide keyword
//[textField resignFirstResponder];
// Clear text field
textView.text = @"";
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *responseString = [request responseString];
//NSDictionary *responseDict = [responseString JSONValue];
//NSLog(@"%@",responseDict);
//NSArray *colorsArray = [responseDict valueForKeyPath:@"colors"];
NSArray *colorsArray = [responseString JSONValue];
NSLog(@"%@",colorsArray);
NSEnumerator *enumerator = [colorsArray objectEnumerator];
NSDictionary* item;
while (item = (NSDictionary*)[enumerator nextObject]) {
NSLog(@"ID = %@", [item objectForKey:@"ID"]);
NSLog(@"Color = %@",[item objectForKey:@"Color"]);
NSString *teststring = [item objectForKey:@"Color"];
textView.text = teststring;
}
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
textView.text = error.localizedDescription;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment