通过Facebook登录确认传递视图控制器 [英] Passing View Controllers With Facebook Login Confirmation

查看:71
本文介绍了通过Facebook登录确认传递视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全感到难过,当有人成功登录facebook时,如何使我的应用程序从登录视图控制器推送到主视图控制器(使用swift).我知道这是一个不好的灵感,但我想像Tinder一样进行登录,在该体验中,您必须通过fb登录才能继续进入该应用程序.我的应用程序大部分已经完成,但是此登录问题是一个巨大的障碍.预先感谢您的协助.

I am completely stumped guys, how do I get my app to push from my login view controller to my home view controller (using swift) when someone successfully logs in with facebook. I know this is a bad inspiration but I would like to make the login experience like Tinder's where you must login through fb to continue into the app. I have the bulk of my application already finished but this login problem has been a huge roadblock. Thanks in advance for any assistance.

推荐答案

在应用中执行此操作的一种方法是在AppDelegate中加载MainViewController.

One way we did it in our app is in our AppDelegate, load a MainViewController.

此视图控制器始终存在于导航堆栈中,它是根视图控制器.

This view controller always exist on the navigation stack, it is the root view controller.

MainViewController中,我们检查是否存在Facebook会话.

In the MainViewController, we check for the existence of the Facebook session.

如果存在,则显示按普通LandingPageViewController;否则,如果不存在,则按LoginViewController.

If it exists, we show push the normal LandingPageViewController, otherwise, if it doesn't exist, we push the LoginViewController.

如果您使用的不是视图控制器的独立Singleton,则要通过Facebook进行身份验证,可以发布notification,您应该在MainViewController中观察到.

If you're using a standalone Singleton that isn't a view controller, to do your authentication with Facebook, you can post a notification, which you should observe in your MainViewController.

收到此通知后,您可以执行推式视图控制器操作.

Upon receiving this notification, you can perform the push view controller action.

下面的伪代码在Objective C中,但是您可以与Swift一起使用.

Below pseudo-code is in Objective C but you can follow along with Swift.

#import "MainViewController.h"

-(void)didFinishLaunchingWithOptions....
{
    // pseudo-code

    MainViewController *mainVC = [[MainViewController alloc] init];

    [self.navigationController pushViewController:mainVC];
}

MainViewController.m

-(void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fbLoginSuccess) name:@"notifLogin" object:nil];

    // check if logged into FB Session
    if(FBSession exists...)
    {
        LandingPageViewController *landingVC = [[LandingPageViewController alloc] init];

        [self.navigationController pushViewController:landingVC];
    }
    else
    {
        LoginViewController *loginVC = [[LoginViewController alloc] init];

        [self.navigationController pushViewController:loginVC];
    }
}

// callback method for facebook success
-(void)fbLoginSuccess
{
    // push view controller here
    LandingPageViewController *landingVC = [[LandingPageViewController alloc] init];

    [self.navigationController pushViewController:landingVC];
}

这篇关于通过Facebook登录确认传递视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆