4

I'm using the CocoaLibSpotify library to develop an iOS application that will utilize the Spotify API. I've got it just about where I want it, but I've run into a bit of a problem.

When the user touches my "Logout of Spotify" button, I execute the following code:

-(IBAction)logoutButtonTouched:(id)sender
{
    // Clear out the user's settings that I am saving.
    NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
    [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];

    [[SPSession sharedSession] logout:^(void) {
        SPLoginViewController *controller = [SPLoginViewController loginControllerForSession:[SPSession sharedSession]];
        controller.allowsCancel = NO;
    }];
}

This does indeed logout the user and display the SPLoginViewController, but my problem is, the username and password field still contain the values that they'd logged-in with. Does anyone know of a way to clear these fields when I display the SPLoginViewController?

skink
  • 5,133
  • 6
  • 37
  • 58

1 Answers1

2

This functionality isn't in the login controller, which is indeed a bug.

You can do it like this. Please note that this is really fragile code and will fail if any internal detail of the login controller changes, and it will in the future:

SPLoginViewController *controller = [SPLoginViewController loginControllerForSession:[SPSession sharedSession]];

id internalLoginViewController = [controller.viewControllers objectAtIndex:0];
UITextField *loginField = [internalLoginViewController valueForKey:@"usernameField"];
UITextField *passwordField = [internalLoginViewController valueForKey:@"passwordField"];
loginField.text = @"";
passwordField.text = @"";
iKenndac
  • 18,730
  • 3
  • 35
  • 51