5

In my LoginViewController, I implemented the FBSDKLoginButtonDelegate and imported the FBSDKLoginKit & FBSDKCoreKit. My code in viewDidLoad is as appears:

    //setting up facebook login button
    var facebookLogin = FBSDKLoginButton()
    //want this button to conform to this protocol
    facebookLogin.delegate = self
    facebookLogin.readPermissions = ["public_profile", "email",   "user_friends"]
    facebookLogin.frame = CGRectMake(20, 359, 335, 30)
    self.view.addSubview(facebookLogin)

Here's the code for the button:

    public func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult 
         result: FBSDKLoginManagerLoginResult!, error: NSError!) {

    if error != nil {
        print(error.localizedDescription)
        return
    } else {
      print("No error")
      self.performSegueWithIdentifier("loginToFeed", sender: self)
    }

}

After logging in, the page stays at this white screen instead of going back to the app. So I go ahead and press "Done" to manually go back to the app and my console prints that there is no error and it proceeds to going to the feed. Now the next part that's interesting is that I'm not logged in despite there being no error at login. Do you know what's going on here? Am I missing a step?

Michael McKenna
  • 811
  • 1
  • 11
  • 24
  • 1
    Turns out that on iOS 9 when UIApplicationDelegate's `application:openURL:options:` is implemented, `application:openURL:sourceApplication:annotation:` will not get called. http://stackoverflow.com/a/32300235/3052059 – Thomás Pereira Sep 12 '16 at 19:35

3 Answers3

4

As stated above missing app delegate but in two places.

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

and

func application(application: UIApplication,
    openURL url: NSURL,
    sourceApplication: String?,
    annotation: AnyObject) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(
            application,
            openURL: url,
            sourceApplication: sourceApplication,
            annotation: annotation)
}
Vadim
  • 1,131
  • 17
  • 16
0

The AppDelegate was missing:

func application(application: UIApplication,
             openURL url: NSURL,
             sourceApplication: String?,
             annotation: AnyObject?) -> Bool {
  return FBSDKApplicationDelegate.sharedInstance().application(application,
                                                  openURL: url,
                                                  sourceApplication: sourceApplication,
                                                         annotation: annotation)
 }
Michael McKenna
  • 811
  • 1
  • 11
  • 24
  • I edited it so the last bracket was included. You might've copy and pasted it without it? Sorry, this was the fix for me. Run through the set up instructions and double check to see if you missed something. That's what I did, you never know! – Michael McKenna Jan 22 '16 at 02:33
0

Here's my situation: I could use myapp to login with fb. Then when I close the app (back to home screen) and enter the app again, it presents me a blank screen. And I solved it by these:

In the app delegate:

func applicationDidBecomeActive(application: UIApplication) {
    FBSDKAppEvents.activateApp()
}

Also, I'm using the bridging file from this article: http://www.brianjcoleman.com/tutorial-how-to-use-login-in-facebook-sdk-4-0-for-swift/

The bridging file looks like this:

#ifndef Bridging_Header_h
#define Bridging_Header_h

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

#endif /* Bridging_Header_h */