我的设置非常简单:
//AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame:UIScreen.main.bounds) //puts a rectange the same size of the screen
window?.rootViewController = MainController()
window?.makeKeyAndVisible() //make the window and keyboard available for window
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
return handled
}
.....
}
//Main Controller
import Foundation
import UIKit
import Alamofire
class MainController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(SplashController().view)
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(changeView), userInfo: nil, repeats: false)
}
func changeView() {
let authController = Authenticate()
view.addSubview(authController.view)
}
}
//View Controller
import Foundation
import UIKit
import FacebookLogin
import FBSDKLoginKit
class Authenticate: UIViewController,FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let loginButton = FBSDKLoginButton()
loginButton.delegate = self
loginButton.center = view.center
view.addSubview(loginButton)
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
print("DID LOG OUT!!!")
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
print("Login Delegate callback")
if error != nil {
print(error)
return
}
print("successfully logged into facebook")
}
func loginButtonWillLogin(_ loginButton: FBSDKLoginButton!) -> Bool {
print("WILL LOGIN")
return true
}
}
一般情况下,登录过程一切正常(我得到FB提示,登录,带回应用程序等)。
但是,代理方法永远不会触发。我从来没有看到" DID LOG OUT"或者"登录代表回拨"或者"成功登录Facebook"。
我错过了什么?
提前感谢您的帮助/建议。