Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
Modernize example code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Renskers committed Nov 19, 2013
1 parent f107874 commit 02f7705
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions Example/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)viewDidLoad {

// Check if we're logged in with a valid session
[[LastFm sharedInstance] getSessionInfoWithSuccessHandler:^(NSDictionary *result) {
[self.loginButton setTitle:[NSString stringWithFormat:@"Logout %@", [result objectForKey:@"name"]]];
[self.loginButton setTitle:[NSString stringWithFormat:@"Logout %@", result[@"name"]]];
[self.loginButton setAction:@selector(logout)];
} failureHandler:^(NSError *error) {
// No, show login form
Expand All @@ -43,15 +43,6 @@ - (void)viewDidAppear:(BOOL)animated {
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}

- (void)viewDidUnload {
[self setLoginFormView:nil];
[self setUsernameField:nil];
[self setPasswordField:nil];
[self setLoginButton:nil];
[self setTableView:nil];
[super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
Expand All @@ -67,20 +58,20 @@ - (IBAction)hideLoginForm {
- (IBAction)loginButtonPressed {
[[LastFm sharedInstance] getSessionForUser:self.usernameField.text password:self.passwordField.text successHandler:^(NSDictionary *result) {
// Save the session into NSUserDefaults. It is loaded on app start up in AppDelegate.
[[NSUserDefaults standardUserDefaults] setObject:[result objectForKey:@"key"] forKey:SESSION_KEY];
[[NSUserDefaults standardUserDefaults] setObject:[result objectForKey:@"name"] forKey:USERNAME_KEY];
[[NSUserDefaults standardUserDefaults] setObject:result[@"key"] forKey:SESSION_KEY];
[[NSUserDefaults standardUserDefaults] setObject:result[@"name"] forKey:USERNAME_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];

// Also set the session of the LastFm object
[LastFm sharedInstance].session = [result objectForKey:@"key"];
[LastFm sharedInstance].username = [result objectForKey:@"name"];
[LastFm sharedInstance].session = result[@"key"];
[LastFm sharedInstance].username = result[@"name"];

// Dismiss the keyboard
[self.usernameField resignFirstResponder];
[self.passwordField resignFirstResponder];

// Show the logout button
[self.loginButton setTitle:[NSString stringWithFormat:@"Logout %@", [result objectForKey:@"name"]]];
[self.loginButton setTitle:[NSString stringWithFormat:@"Logout %@", result[@"name"]]];
[self.loginButton setAction:@selector(logout)];
self.loginFormView.hidden = YES;
} failureHandler:^(NSError *error) {
Expand Down

0 comments on commit 02f7705

Please sign in to comment.