我有一个使用Parse创建PFLogInViewController的视图应用程序。在可以访问BeaconViewController之前,用户必须通过Facebook进行身份验证 - 这很正常。我的问题在于注销部分 - 在用户的会话被销毁之后,我需要重新出现PFLogInViewController
。我尝试通过弹出RootViewController
来实现这一点,但这并不能解决问题。
以下是BeaconViewController.m
,其中包含身份验证和注销逻辑
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
FBRequest *request = [FBRequest requestForMe];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
[self dismissViewControllerAnimated:YES completion:nil];
[self pictureRequest];
}
else if (error) {
NSLog(@"facebook session was invalid");
[self logoutButtonAction:nil];
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsFacebook;
login.delegate = self;
NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];
login.facebookPermissions = permissionsArray;
[self presentViewController:login animated:YES completion:nil];
}
else {
NSLog(@"Some other error: %@", error);
}
}];
}
- (IBAction)logoutButtonAction:(id)sender {
[PFUser logOut];
[self.navigationController popToRootViewControllerAnimated:YES];
}
答案 0 :(得分:0)
尝试使用:
[self.navigationController popViewControllerAnimated:YES];
答案 1 :(得分:0)
将您的segue类型更改为推送。在IBAction操作方法中添加此行代码。
- (IBAction)logoutButtonAction:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
答案 2 :(得分:0)
我通过抽象将PFLogInViewController
呈现为辅助方法并在注销时调用它的逻辑来解决这个问题。
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
FBRequest *request = [FBRequest requestForMe];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
[self dismissViewControllerAnimated:YES completion:nil];
[self pictureRequest];
}
else if (error) {
NSLog(@"facebook session was invalid");
[self logoutButtonAction:nil];
[self presentPFLogInViewController];
}
else {
NSLog(@"Some other error: %@", error);
}
}];
}
-(void)presentPFLogInViewController {
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsFacebook;
login.delegate = self;
NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];
login.facebookPermissions = permissionsArray;
[self presentViewController:login animated:YES completion:nil];
}
- (IBAction)logoutButtonAction:(id)sender {
[PFUser logOut];
[self presentPFLogInViewController];
}