2016-04-24 186 views
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. 
} 

} 

回答

1

據我知道,因爲我看到你的問題做了進一步的研究,但仍無法跳過第二個屏幕。第二屏幕是指您必須點擊「登錄」的網頁,並提供有關應用程序如何與Facebook互動的詳細信息。即使是這個網站的應用程序,當你使用Facebook登錄時,你也會到那裏。如果它改變了,或者我誤會了,我會更新這篇文章。由於我剛剛加入該網站,我無法發佈圖片:)但我希望我們正在談論同樣的事情。