Reputation: 1823
I'm following this tutorial to integrate Facebook AccountKit with Swift. Almost everything is working but delegate functions are not called and I don't know why this is no happening.
My code:
import UIKit
import AccountKit
class LoginViewController: UIViewController,AKFViewControllerDelegate {
//
var _accountKit: AKFAccountKit?
var _pendingLoginViewController: AKFViewController?
var _authorizationCode: String?
//
override func viewDidLoad() {
super.viewDidLoad()
if _accountKit == nil {
_accountKit = AKFAccountKit(responseType: .accessToken)
}
_pendingLoginViewController = _accountKit!.viewControllerForLoginResume()
_pendingLoginViewController?.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func prepareLoginViewController(loginViewController: AKFViewController) {
loginViewController.delegate = self
}
@IBAction func loginWithPhone(_ sender: UIButton) {
let inputState = NSUUID().uuidString
let vc: AKFViewController = _accountKit!.viewControllerForPhoneLogin(with: nil, state: inputState)
self.prepareLoginViewController(loginViewController: vc)
self.present(vc as! UIViewController, animated: true, completion: nil)
}
private func viewController(viewController: UIViewController!, didCompleteLoginWithAuthorizationCode code: String!, state: String!) {
print("1")
}
private func viewController(viewController: UIViewController!, didCompleteLoginWithAccessToken accessToken: AKFAccessToken!, state: String!) {
print("2")
}
private func viewController(viewController: UIViewController!, didFailWithError error: Error!) {
print("3")
}
private func viewControllerDidCancel(viewController: UIViewController!) {
print("4")
}
}
Swift version: 3.2
I belice is something to do with the swift version (I believe this tutorial is for 2.x) but i had a similar code from an example in Swift 3 and is working. So I don't know what is going wrong.
Upvotes: 2
Views: 832
Reputation: 157
You don't need to cahnge methods to private.
Change delegate methods to the following:
func viewController(_ viewController: (UIViewController & AKFViewController)!,
didCompleteLoginWith accessToken: AKFAccessToken!, state: String!) {
}
func viewController(_ viewController: (UIViewController & AKFViewController)!, didCompleteLoginWithAuthorizationCode code: String!, state: String!) {
}
func viewController(_ viewController: (UIViewController & AKFViewController)!, didFailWithError error: Error!) {
}
func viewControllerDidCancel(_ viewController: (UIViewController & AKFViewController)!) {
print("canceled")
}
Upvotes: 4
Reputation: 408
Problem might be that your delegate functions are all private and so the AKFViewController is unable to invoke them. Try making them public and see if you still can't get the callbacks
Upvotes: 0