Функции обратного вызова набора учетных записей не запускаются (только viewControllerDidCancel) - PullRequest
0 голосов
/ 27 ноября 2018

Я пытался установить функцию как приватную, пытался использовать функцию расширения AFViewControllerDelgate вне viewcontroller и ничего не работает.Только didCancel работает.Похоже, они изменили методы делегата или что-то в этом роде.И я не знаю, почему нет официальной документации AccountKit, написанной на swift

Ниже приведен код:

import UIKit
import AccountKit
import FBSDKCoreKit

// MARK: - LoginViewController: UIViewController

final class LoginViewController: UIViewController, 
AKFViewControllerDelegate {

// MARK: Properties

fileprivate var accountKit = AKFAccountKit(responseType: .accessToken)
fileprivate var dataEntryViewController: AKFViewController? = nil
fileprivate var showAccountOnAppear = false



// MARK: View Life Cycle

override func viewDidLoad() {
    super.viewDidLoad()
    showAccountOnAppear = accountKit.currentAccessToken != nil
    dataEntryViewController = accountKit.viewControllerForLoginResume() as? AKFViewController


}


override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    if showAccountOnAppear {
        showAccountOnAppear = false
        presentWithSegueIdentifier(LoggedInViewController(), animated: animated)
    } else if let viewController = dataEntryViewController {
        if let viewController = viewController as? UIViewController {
            present(viewController, animated: animated, completion: nil)
            dataEntryViewController = nil
        }
    }

    self.navigationController?.isNavigationBarHidden = true

}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    self.navigationController?.isNavigationBarHidden = false
}

// MARK: Actions

@IBAction func loginWithPhone(_ sender: AnyObject) {
    FBSDKAppEvents.logEvent("loginWithPhone clicked")
    if let viewController = accountKit.viewControllerForPhoneLogin() as? AKFViewController {
        prepareDataEntryViewController(viewController)
        if let viewController = viewController as? UIViewController {
            present(viewController, animated: true, completion: nil)
        }
    }
}

@IBAction func loginWithEmail(_ sender: AnyObject) {
    FBSDKAppEvents.logEvent("loginWithEmail clicked")
    if let viewController = accountKit.viewControllerForEmailLogin() as? AKFViewController {
        prepareDataEntryViewController(viewController)
        if let viewController = viewController as? UIViewController {
            present(viewController, animated: true, completion: nil)
        }
    }
}

// MARK: Helper Functions

func prepareDataEntryViewController(_ viewController: AKFViewController){
    viewController.delegate = self
}

fileprivate func presentWithSegueIdentifier(_ segueIdentifier: UIViewController, animated: Bool) {
    if animated {
        present(segueIdentifier, animated: false)
    } else {
        UIView.performWithoutAnimation {
            self.present(segueIdentifier, animated: true)
        }
    }
}


func viewController(viewController: UIViewController!, didCompleteLoginWithAccessToken accessToken: AKFAccessToken!, state: String!) {
    print("did complete login with access token \(accessToken.tokenString) state \(state)")
    //...
}

func viewController(_ viewController: (UIViewController & AKFViewController)!,  didCompleteLoginWithAuthorizationCode code: String!, state: String!) {
    print("Nem sei")
}
func viewController(_ viewController: (UIViewController & AKFViewController)!, didFailWithError error: Error!) {
    // ... implement appropriate error handling ...
    print("\(viewController) did fail with error: \(error.localizedDescription)")
}

func viewControllerDidCancel(_ viewController: (UIViewController & AKFViewController)!) {
    print("Cancel")
}

}
...