Created
December 6, 2012 21:59
-
-
Save jlee42/4228886 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[[RKObjectManager sharedManager].HTTPClient postPath:@"/api/v2/json/api_users/sign_in" parameters:params success:^(AFHTTPRequestOperation *operation, id JSON) | |
{ | |
NSString *jsonString = [[NSString alloc] initWithData:JSON encoding:NSUTF8StringEncoding]; | |
NSDictionary *objectDescriptor = [jsonString JSONValue]; | |
NSString *authToken = [objectDescriptor valueForKey:@"auth_token"]; | |
if (authToken != nil) { | |
[[NSUserDefaults standardUserDefaults] setValue:authToken forKey:@"auth_token"]; | |
[[NSUserDefaults standardUserDefaults] setValue:usernameField.text forKey:@"authentication_username"]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; | |
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"auth_token"] length] > 0) { | |
usernameField.enabled = NO; | |
passwordField.hidden = YES; | |
authorizeDeviceButton.hidden = YES; | |
deauthorizeDeviceButton.hidden = NO; | |
} | |
[[NSUserDefaults standardUserDefaults] synchronize]; | |
[[RKObjectManager sharedManager].operationQueue cancelAllOperations]; | |
} | |
} failure:^(AFHTTPRequestOperation *operation, NSError *error) | |
{ | |
NSLog(@"Error: %@", operation.response); | |
if ([operation.response statusCode] == 401) { | |
UIAlertView *alert = [[UIAlertView alloc] | |
initWithTitle:@"Failure" | |
message:@"A network error has occurred." | |
delegate:nil | |
cancelButtonTitle:@"OK" | |
otherButtonTitles:nil]; | |
[alert show]; | |
} | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment