0

我是一个快速的初学者,并且已经为 IOS 实现了 FB 登录。我想知道如何通过快速应用程序切换来做到这一点,并在不转到 Facebook 登录表单的情况下留在应用程序上。

这是我的 ViewController.swift 处理 FB 登录的代码:

import UIKit
import Foundation

class FacebookLoginViewController : UIViewController, FBSDKLoginButtonDelegate {

let loginButton: FBSDKLoginButton = {
    let button = FBSDKLoginButton()
    button.readPermissions = ["public_profile","email","user_friends"]
    return button
}()

override func viewDidLoad() {
    super.viewDidLoad()

    view.addSubview(loginButton)
    loginButton.center = view.center
    loginButton.delegate = self

    if let token = FBSDKAccessToken.currentAccessToken() {
        fetchProfile()
    }
}

func fetchProfile() {
    print("User Profile fetched")


    redirectToHome()

}

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
    print("User has successfully logged on.")

    redirectToHome()
}

func redirectToHome() {

    let storyboard:UIStoryboard = UIStoryboard(name:"Main", bundle: nil)

    let homeFeed: UIViewController = storyboard.instantiateViewControllerWithIdentifier("homeFeed") as UIViewController

    self.presentViewController(homeFeed, animated: true, completion: nil)
}

func loginButtonWillLogin(loginButton: FBSDKLoginButton!) -> Bool {
    return true
}

func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
    print("User has logged out")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}
4

1 回答 1

1

据我所知,自从我看到你的问题做了进一步的研究,仍然不可能跳过第二个屏幕。第二个屏幕是指您必须点击“登录”的网页,它提供了有关应用程序如何与 Facebook 交互的详细信息。使用 Facebook 登录时,即使是该网站的应用程序也会将您带到那里。如果它发生变化或者我弄错了,我会更新这篇文章。因为我刚加入这个网站,所以我还不能发布图片:)但我希望我们谈论的是同一件事。

于 2017-04-18T11:53:52.283 回答