I'm working on my first app with a facebook login, and am unable to get a segue to trigger once I'm logged in. The facebook login triggers just fine and logs me in, then I'm dumped back to the login VC.
Here's where I'm triggering the 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!")
}
}
Here are my other FB Login methods:
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)
}
})
}
}
My 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()
}
}
In my App Delegate:
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)
// ...
}
The segue is wired in IB with an identifier of "SearchVC"
Edit: I initially tried performing the segue in the completion block of FBSDKGraphRequest, but it doesn’t trigger there either
I’m not asking how to perform a segue as the suggested duplicate question indicates