简体   繁体   中英

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. 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).

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. 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. I'm new but I hope this helps to some extent. If I've misunderstood your question, please let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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