Facebook登录后,Swift项目无法正确选择 [英] Swift project not segue-ing properly after Facebook login

查看:63
本文介绍了Facebook登录后,Swift项目无法正确选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初的ViewController,LoginViewController.swift:

The initial ViewController, LoginViewController.swift:

import UIKit

class LoginViewController: UIViewController, FBSDKLoginButtonDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do view setup here.

        if (FBSDKAccessToken.currentAccessToken() != nil)
        {
            // User is already logged in, do work such as go to next view controller.
            performSegueWithIdentifier("loginSegue", sender: nil)
            print("segued due to login")
        }
        else
        {
            let loginView : FBSDKLoginButton = FBSDKLoginButton()
            self.view.addSubview(loginView)
            loginView.center = self.view.center
            loginView.readPermissions = ["public_profile", "user_friends"]
            loginView.delegate = self
        }
    }

    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
        print("User Logged In")
        if ((error) != nil)
        {
            // Process error
        }
        else if result.isCancelled {
            // Handle cancellations
        }
        else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            performSegueWithIdentifier("loginSegue", sender: nil)
            /*
            if result.grantedPermissions.contains("email")
            {
                // Do work
            }
            */
        }
    }

    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
        print("User Logged Out")
    }

}

每次启动应用程序时,都会在终端上显示

由于登录而被隔离"的字样,因此可以清楚地看到if语句以及performSegueWithIdentifier()行.但是,由于LoginViewController停留在屏幕上,并且未显示下一个ViewController,因此实际上并未执行此命令.我也尝试添加该行:

"segued due to login" is printed to the terminal upon starting up the app every time, so the if-statement is clearly being reached and also the performSegueWithIdentifier() line. However, the segue is not actually performed as the LoginViewController stays on the screen and the next ViewController is not displayed. I have also tried adding the line:

    performSegueWithIdentifier("loginSegue", sender: nil)

在其他几个我知道程序正在到达的位置,就像在super.viewDidLoad()之后一样.因此,该问题似乎是特定于segue的,而问题似乎并非与Facebook的登录有关.

in several other locations I know the program is reaching, like right after super.viewDidLoad(). So, the problem seems to be specific to the segue and the problem does not seem to be with Facebook's login.

我提供了带有segue属性的情节提要的屏幕截图:

I have included a screenshot of the storyboard with the segue's attributes:

如果需要,我可以包含任何其他文件.我也怀疑这可能是与

I can include any other files if needed. I also suspect it could be a similar type bug as this stackoverflow problem. I have tried deleting the placeholders in my UITextViews in all of my ViewControllers, but this did not solve the problem.

推荐答案

好的,这就是您的应用程序:didFinishLaunching:withOptions的外观.

Ok so here's how your application:didFinishLaunching:withOptions should look like.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

    let mainStoryboard = UIStoryboard.init(name: "Main", bundle: nil)
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    var initialViewController: UIViewController

    if(FBSDKAccessToken.currentAccessToken() != nil){
        let vc = mainStoryboard.instantiateViewControllerWithIdentifier("someOtherViewController") as! SomeOtherViewController
        initialViewController = vc
    }else{
        initialViewController = mainStoryboard.instantiateViewControllerWithIdentifier("loginViewController")
    }

    self.window?.rootViewController = initialViewController

    self.window?.makeKeyAndVisible()

    return true
}

这篇关于Facebook登录后,Swift项目无法正确选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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