I am new to iPhone programming.Using below code i am login into Facebook and fetching data.But here problem is if click on the Loginwithfacebook button Facebook dialog box opening.there i am enter username and password of Facebook after that if again click on same button then i am getting user data.But i don't want to click on double time.And also once i login in Facebook.inside the app where i want to fetch user data at that time i don't to login one more time until i click on logout.Please give me best idea.
-(void)LoginWithFacebookk:(id)sender
{
if (!FBSession.activeSession.isOpen) {
FBSession *session = [[FBSession alloc] init];
// Set the active session
[FBSession setActiveSession:session];
// Open the session
[session openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error)
{
}];
}
else
{
NSLog(@"open response");
FBRequest* friendsRequest = [FBRequest requestForMe];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary <FBGraphUser> *user,NSError *error) {
NSString *emailiddd=[NSString stringWithFormat:@"%@",[user objectForKey:@"email"]];
NSLog(@"%@",emailiddd);
NSString *post = [NSString stringWithFormat:@"email=%@",emailiddd];
NSLog(@"%@",post);
}];
}
}
}
if you are checking sample code of provide by Facebook in
FacebookSDK
there is one sample SessionLoginSampleplease check how did work:-You have to configur you app like this:-
in Native iOS app you have to set you app Bundle Id that you are using in to you Project for example(com.compame.projecname)
For implement in to your Project Here i put the explain.
in .h file create One Button with
IBOutlet
and connect this button in to xib as we did normallyin .m File @implementation LoginViewController @synthesize profilePic = _profilePic;
NOTE:- If you are trying to set Image of logged in user using
FBProfilePictureView
do not forget add[FBProfilePictureView class];
in to app Delegate like BellowHere it is a sample code for you Sample code Facebook log-in with Image