简体   繁体   English

iOS Twitter + OAuth检查用户是否已登录

[英]iOS Twitter+OAuth check if user is logged in

I'm developing an app in which I want to give the user the option to be logged in with Twitter. 我正在开发一个应用程序,在该应用程序中,我希望为用户提供使用Twitter登录的选项。 My problem is that I want to check if the user is logged before given access to certain functions. 我的问题是我想在授予对某些功能的访问权之前检查用户是否已登录。 Say I have a view and I want to show different content depending on the users is logged in or not. 说我有一个视图,并且我想根据是否登录的用户显示不同的内容。 I know I can log the user in when opening the app, but I don't want to show the login screen every time if the user choose not to log in. (I'm using the Twitter+OAuth/MGTwitterEngine framework). 我知道我可以在打开应用程序时登录用户,但是如果用户选择不登录,则我不想每次都显示登录屏幕。(我使用的是Twitter + OAuth / MGTwitterEngine框架)。

How can I set up a control like that? 我该如何设置这样的控件? Any tips is appreciated! 任何提示表示赞赏!

Seems like you would want to save the authorization token in NSUserDefaults. 似乎您想将授权令牌保存在NSUserDefaults中。 Then, on launch, you would check for that token 然后,在启动时,您将检查该令牌

if (![[NSUserDefaults standardUserDefaults] objectForKey:@"whatever_you_call_your_auth_token") {
//send the user to twitter login
} else {
//set isLoggedInViaTwitter:YES
}

So if you have a boolean value like isLoggedInViaTwitter, and you set that to YES or NO based on whether the auth token is present in NSUserDefaults, you can use the value of that to determine what content to present in your views. 因此,如果您具有isLoggedInViaTwitter之类的布尔值,并根据NSUserDefaults中是否存在auth令牌将其设置为YES或NO,则可以使用该值确定要在视图中呈现的内容。 I'm new but I hope this helps to some extent. 我是新手,但我希望这在一定程度上有所帮助。 If I've misunderstood your question, please let me know. 如果我误解了您的问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM