0

Im は迅速な初心者であり、IOS の FB ログインを既に実装しています。Fast-App-Switching でそれを行う方法と、Facebook ログインフォームに移動せずにアプリにとどまる方法を考えていました。

FB ログインを処理する ViewController.swift のコードは次のとおりです。

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