views:

671

answers:

3

Hey, I am using facebook connect sdk for iPhone, every time I start my app and click login, there would be a login screen asking me to input my name and password.

Is there any way to keep me logged in once I input my name and password, that's to say, I needn't to input my name and password again the next time I start my app?

A: 

Store the password (or the requisite hash of it) somewhere.

Anon.
A: 

You need to use the keychain. Have a look to this article: http://log.scifihifi.com/post/55837387/simple-iphone-keychain-code

nico
Thanks Nicolas, But the password and username are handled by Facebook Connect, I cant get it. It's a facebook standard login view, any idea that I can keep it as logged in?
Yuhui
Ho yes got it. You probably need to use [session resume]. The documentation says that the facebook session object is stored in the iPhone's preferences and can be reused later: http://wiki.developers.facebook.com/index.php/Facebook_Connect_for_iPhone#Logging_In
nico
+3  A: 

According to the Platform Guidelines 1.3, you are not allowed to store a Facebook user's credentials. The best you can hope for is that your user checks the "Keep me logged in" option. She should be able to post without having to login any time soon, even if she restarts your app.

The following snippet works with the above scenario:

NSString *fbAPIKey = ...;
NSString *fbApplicationSecret = ...;
_session = [[FBSession sessionForApplication:fbAPIKey secret:fbApplicationSecret delegate:self] retain];

// checks whether session can be resumed - whether login is required
if (![_session resume]) {
    FBLoginDialog *loginDialog = [[[FBLoginDialog alloc] initWithSession:_session] autorelease];
    [loginDialog show];
}
Nick Toumpelis