Facebook登录-停留在白色网页SWIFT [英] Facebook login - stays at white web page SWIFT

查看:208
本文介绍了Facebook登录-停留在白色网页SWIFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的LoginViewController中,我实现了FBSDKLoginButtonDelegate并导入了FBSDKLoginKit& FBSDKCoreKit.我在viewDidLoad中的代码如下所示:

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)

这是按钮的代码:

    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?

推荐答案

如上所述,缺少应用程序委托,但有两个地方.

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)
}

func application(application: UIApplication,
    openURL url: NSURL,
    sourceApplication: String?,
    annotation: AnyObject) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(
            application,
            openURL: url,
            sourceApplication: sourceApplication,
            annotation: annotation)
}

这篇关于Facebook登录-停留在白色网页SWIFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆