Facebook登录后,触发SEGUE



我正在使用Facebook登录工作的第一个应用程序,并且一旦我登录就无法触发。Facebook登录触发器正好很好,并记录了我,然后我倒回登录VC。

这是我触发segue的地方:

func loginButtonDidCompleteLogin(_ loginButton: LoginButton, result: LoginResult) {
    switch result {
    case .failed(let error):
        print(error)
        break
    case .success(_,_,_):
        print("login succeeded!")
        self.performSegue(withIdentifier: "SearchVC", sender: self.user)
    case .cancelled:
        print("Canceled!")
    }
}

这是我的其他FB登录方法:

func facebookButtonClicked(sender: UIButton) {
    let loginManager = LoginManager()
    loginManager.logIn(readPermissions: [.publicProfile], viewController: self) { loginResult in
        switch loginResult {
        case .failed(let error):
            print(error)
        case .cancelled:
            print("User cancelled login")
        case .success(let grantedPermissions, let declinedPermissions, let accessToken):
            print("Logged in")
            self.getFBUserData()
        }
    }
}
func getFBUserData() {
    if FBSDKAccessToken.current() != nil {
        FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, email"]).start(completionHandler: { (connection, result, error) -> Void in
            if error == nil {
                self.userData = result as! [String : AnyObject]
                print(result!)
                print(self.userData)
            }
        })
    }
}

我的segue:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "SearchVC", let searchVC = segue.destination as? SearchVC { 
        searchVC.user = sender as? User ?? User()
    }
}

在我的应用程序委托中:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func applicationWillResignActive(_ application: UIApplication) {
    FBSDKAppEvents.activateApp()
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
    return SDKApplicationDelegate.shared.application(app, open: url, options: options)
}
func applicationDidBecomeActive(application: UIApplication) {
    // Call the 'activate' method to log an app event for use
    // in FB analytics and advertising reporting.
    AppEventsLogger.activate(application)
    // ...
}

segue与" searchvc"的标识符

连接到IB中

编辑:我最初尝试在fbsdkgraphrequest的完成块中执行SEGUE,但它也不会触发

我不是在问如何执行segue,因为建议的重复问题指示

您应该在FBSDKGraphRequest完成中调用Performsegue方法。

  func getFBUserData(){
    if((FBSDKAccessToken.current()) != nil){
      FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, email"]).start(completionHandler: { (connection, result, error) -> Void in
        if (error == nil){
          self.userData = result as! [String : AnyObject]
          print(result!)
          print(self.userData)
          self.performSegue(withIdentifier: "SearchVC", sender: self)
        }
      })
    }
  }
}

该项目被错误。我还有另一个没有执行代码的问题,以及这里和那里的其他一些杂项。删除我的LoginVC文件并重新创建解决所有问题

最新更新