0

In my app, I have a Facebook login in my first view controller which redirects to my next view controller after a successful login that has a LinkedIn Login option.

However, after the LinkedIn Login button is pressed, I receive this error.

2016-10-17 23:00:42.588 Frieyo[86134:1636422] -canOpenURL: failed for URL: "linkedin://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
2016-10-17 23:00:42.593 Frieyo[86134:1636422] Warning: Attempt to present <UINavigationController: 0x7f9fa409ba00> on <Frieyo.TutorialViewController: 0x7f9fa2c04430> whose view is not in the window hierarchy!

I know it's not a problem with opening the LinkedIn URL because my App Delegate is handling those URL's correctly AND when I set the LinkedIn view controller as my initial view controller the login WORKS!

Apparently these answers: iOS: Warning "attempt to present ViewController whose view is not in the window hierarchy" and whose view is not in the window hierarchy indicate that I should put this method in my viewDidAppear method; however, that is not relevant because I am redirecting to another view after a successful login.

The problem (I assume) lies within the view stack. Here's is how I'm am transitioning from the first view controller to the LinkedIn VC.

   let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
   let nextViewController = storyBoard.instantiateViewController(withIdentifier: "VerifyLinkedInViewController") as! VerifyLinkedInViewController
   self.present(nextViewController, animated:true, completion:nil)

How exactly do I re-write to avoid -"whose view is not in the window hierarchy!" ?

Community
  • 1
  • 1
Rohit Tigga
  • 2,313
  • 7
  • 40
  • 78
  • Have You tried with let nextViewController = storyBoard.instantiateViewController(withIdentifier: "VerifyLinkedInViewController") as! UIViewController....? – abdul sathar Oct 20 '16 at 04:11
  • Just tried it. No luck :/ Why did you suggest that? – Rohit Tigga Oct 20 '16 at 04:19
  • window hierarchy in the sense ,your next controller/view is not in the queue to load on window..,you missed something in code/storyboard try to debug in the project(this is the common mistake will happend when we try newly or migrate objc to swift).. – abdul sathar Oct 20 '16 at 04:25
  • How can I reach you for a chat? Just want to clarify. – Rohit Tigga Oct 20 '16 at 04:37
  • OK Sure will do now..... – abdul sathar Oct 20 '16 at 04:39
  • try to check out his answer..http://stackoverflow.com/questions/11862883/whose-view-is-not-in-the-window-hierarchy?noredirect=1&lq=1 – abdul sathar Oct 20 '16 at 04:50
  • I linked that in my original question. ^ I'm trying to understand how that is relevant because this is happening after an @IBAction after a button press. Let me link you to my full code. I am make a pastebin – Rohit Tigga Oct 20 '16 at 04:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/126177/discussion-between-rohit-tigga-and-abdul-sathar). – Rohit Tigga Oct 20 '16 at 04:54
  • You have to find storyboard and your view controller then you can move from linkedin view controller – Jitendra Modi Oct 20 '16 at 06:16

1 Answers1

0

I have just faced this problem, the issue was inside my facebook login method, in the "fromViewController" parameter.

In order to fix it, I had to reference the View Controller that I did the call to the method, instead of instantiate a new one.

EDIT - Code example (that's the one that it's working for me now):

func performFacebookSignIn(viewController: UIViewController) {

    let facebookReadPermissions = ["public_profile", "email"]
    let loginManager = FBSDKLoginManager()

    loginManager.logInWithReadPermissions(facebookReadPermissions, fromViewController: viewController, handler: { (result: FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
        if error != nil {
            print(error)
        } else if result.isCancelled {
            print("User cancelled login.")
        } else {
            print("Facebook sign in!")
        }
    })

Before that, instead of using a "viewController" parameter from the other ViewController where I called the method, I was instantiating a new View Controller in "fromViewController" parameter (I was doing: MyViewController() as UIViewController) and it was getting me this "window hierarchy" error.

I hope it helps you somehow.

Samuel Dias
  • 169
  • 5