Created
September 29, 2012 17:46
-
-
Save swarut/3804692 to your computer and use it in GitHub Desktop.
Objective-C : Requesting and handling a response #objective-c #api #request #handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) request{ | |
NSString *targetUrlString = @"url"; | |
NSURL *targetUrl = [NSURL URLWithString:targetUrlString]; | |
NSData *data = [NSData dataWithContentsOfURL:targetUrl]; | |
[self performSelectorInBackground:@selector(callback:) withObject:data]; | |
} | |
-(void) callBack:(NSData*)respondedData{ | |
NSError *error; | |
NSDictionary *dataDic = [NSJSONSerialization | |
JSONObjectWithData:respondedData | |
options:kNilOptions | |
error:&error]; | |
NSNumber *returnedCode = [dataDic objectForKey:@"StatusCode"]; | |
if([@"200" isEqualToString:[returnedCode stringValue]]){ | |
// do something | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment