How to perform modalSegue?

时光总嘲笑我的痴心妄想 提交于 2019-12-13 06:29:13

问题


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;
    }
}

回答1:


try like this add this line your .h file

@property(strong ,nonatomic) NSMutableDictionary *userinfo;

.m file

add this `@synthesize userinfo`



    - (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);


    [userinfo  setValue: [FBuser name] forKey:@"fbusername"];
//add here all your value which you want

      }
[self performSegueWithIdentifier:@"afterLogin" sender:sender];
                                                  }];
                                                  break;
                                          }
                                      } ];

    }


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSString *identifier = segue.identifier;
   // NSLog(@"prepareForSegue:= %@", identifier);


    if ([segue.identifier isEqualToString:@"afterLogin"]) {

        [segue.destinationViewController setID:userinfo];




    }


}

just add this method in your destination viewcontoller

-(void)setID:(NSMutableDictionary *)value;
{


     // all your details here

      NSLog(@"Got happy userinfo %@", value);

}


来源:https://stackoverflow.com/questions/26362649/how-to-perform-modalsegue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!