I am using FaceBook SDK for iOS.
For login a UIWebView comes and we have to add username and password. I don't want to login like this.
Can the login be done in the background or without opening the UIWebView if user provide the username and password from iOS Application?
FaceBook's SDK doesn't allow that.. they've implemented the oauth login method so that the user don't need to give username and password to the application, user directly input the credentials in the web view and get authenticated via the fb servers. But in response app receives an access token which it can save and and use for future transactions and user don't need to enter his username or password again. This tutorial might be helpful in this regard:
http://www.raywenderlich.com/1488/how-to-use-facebooks-new-graph-api-from-your-iphone-app
Delegate methods are available in the SDK in which you can save the access token.
I am using FaceBook Sdk Older Version, in this u can use of Session through this only one time it will ask for login,
http://www.raywenderlich.com/77/how-to-post-on-facebook-with-your-iphone-app
this tutorial works like u want
you cannot save the retrieve the facebook username and password and you are not suppose to save it in your db due to the privacy issue, what can you do is when the first time your user is login in permisssion ask for offline_access and then you will get an access token which will be valid for indefinitely, you can save this access_token.
-(void)viewDidLoad
{
[super viewDidLoad];
NSString *urlString = @"http://www.XYZ.com";
url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[web loadRequest:request];
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:
@"var field = document.getElementById('ctl00_txtPassword');"
"field.value='%@';",password]];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"var field = document.getElementById('ctl00_txtUsername');"
"field.value='%@';",username]];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView;
{
[self.web stringByEvaluatingJavaScriptFromString:@"fnLogin();"];
}
It Solve your Problem very easily.