加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 如何在CocoaLibSpotify注销上清除用户名和密码?

发布时间:2020-12-16 07:34:24 所属栏目:百科 来源:网络整理
导读:我正在使用 CocoaLibSpotify库开发一个将使用Spotify API的iOS应用程序.我已经得到了我想要的地方,但我遇到了一些问题. 当用户触摸我的“Spotify of Spotify”按钮时,我执行以下代码: -(IBAction)logoutButtonTouched:(id)sender{ // Clear out the user's
我正在使用 CocoaLibSpotify库开发一个将使用Spotify API的iOS应用程序.我已经得到了我想要的地方,但我遇到了一些问题.

当用户触摸我的“Spotify of Spotify”按钮时,我执行以下代码:

-(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;
    }];
}

这确实注销了用户并显示了SPLoginViewController,但我的问题是,用户名和密码字段仍然包含他们登录的值.当我显示SPLoginViewController时,有没有人知道清除这些字段的方法?

解决方法

此功能不在登录控制器中,这确实是一个错误.

你可以这样做.请注意,这是非常脆弱的代码,如果登录控制器的任何内部细节发生变化,将会失败,并且将来会:

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 = @"";

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读