0
我是一個迅速的初學者,並且已經爲IOS實現了FB登錄。我想知道如何通過快速應用切換來做到這一點,並留在應用程序中,而無需轉移到Facebook登錄表單。Swift IOS Facebook登錄Fast-App-Switch
我的繼承人爲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.
}
}