Segue won't trigger after Facebook login with Swift
<p>Thanks in advance for your help!</p>

<p>I am implementing facebook login on a swift app I'm writing, and I am having some trouble performing a segue after the login completes.</p>

<p>As part of FBSDKLoginButtonDelegate, I have two methods:</p>

<pre><code>func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result:
 FBSDKLoginManagerLoginResult!, error: NSError!)
    {}
</code></pre>

<p>and</p>

<pre><code>func loginButtonDidLogOut(loginButton: FBSDKLoginButton!)
    {}
</code></pre>

<p>The login button is implemented correctly, I am able to read permissions/FB tokens, and pass this onto Amazon Cognito.</p>

<p>The strange thing, though, is that I cannot programmatically segue out of the login, into a different view (controller).</p>

<p>Pushing the FB Login Button takes the user to a web browser (the Facebook SDK handles all of this), and the login takes place.</p>

<p>If I place a segue, like:</p>

<pre><code>dispatch_async(dispatch_get_main_queue(), {
        self.performSegueWithIdentifier("segueLoginViewtoHome", sender: nil })
</code></pre>

<p>into loginButton(), it never truly executes (i.e, when the web browser goes away, the user is returned to the view with the login button, not the new view intended by the segue). I believe the line executes before the browser window returns to the view housing the login button (and the segue), but I have no clue how to tell the program to "wait" for the view to become the only one active and visible again to perform the segue.</p>

<p>I believe this is the case, because if I were to put the same segue code into loginButtonDidLogOut(), where no switch to a browser is needed, the segue executes just fine after "log out" is pushed in the sheet that slides up from the bottom of the screen.</p>

<p>This view controller is correctly set as the delegate, as shown by the segue functioning correctly if coded to occur upon logout. </p>

<p>Any help would be much appreciated, apologies for the long question, and thanks!</p>