I'm building an iOS app. I have integrated facebook login in my app and implemented modal segue means when user logged in successfully it goes on next view.
I'm facing a problem that is after logged in i'm not able to go on next view.one thing more i'm not able to do that when user already logged in on my app through facebook and come back after closing the app it should be on Next ViewController not on login screen again.
Storyboard flow is:
Login screen --> Modal Segue --> Navigation Controller --> Next ViewController
This is my code:
- (IBAction)fbLogin:(id)sender {
[FBSession openActiveSessionWithReadPermissions:@[@"email",@"user_location",@"user_birthday",@"user_hometown"]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
switch (state) {
case FBSessionStateOpen:
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
NSLog(@"error:%@",error);
} else {
// retrive user's details at here as shown below
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) {
if (error) {
// Handle error
} else {
NSString *userName = [FBuser name];
NSLog(@"username===%@",userName);
NSLog(@"sesseion=%@",session);
}
}];
NSLog(@"FB user first name:%@",user.first_name);
userName=user.first_name;
NSLog(@"FB user last name:%@",user.last_name);
NSLog(@"FB user birthday:%@",user.birthday);
NSLog(@"FB user location:%@",user.location);
NSLog(@"FB user username:%@",user.username);
NSLog(@"FB user gender:%@",[user objectForKey:@"gender"]);
NSLog(@"email id:%@",[user objectForKey:@"email"]);
NSLog(@"location:%@", [NSString stringWithFormat:@"Location: %@\n\n",
user.location[@"name"]]);
userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [user objectID]];
NSLog(@"image=%@",userImageURL);
}
[self performSegueWithIdentifier:@"afterLogin" sender:sender];
}];
break;
}
} ];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"afterLogin"]) {
PPla *image = [segue destinationViewController];
PPla *name = [segue destinationViewController];
name.proName = [NSString stringWithFormat:userName];
image.proImage = userImageURL;
}
}