KMLoginManager.swift 915 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // KMLoginManager.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lizhe on 2023/8/11.
  6. //
  7. import Foundation
  8. typealias KMLoginCompletion = (_ isSuccess: Bool, _ error: KMAppleLoginErrorType) -> Void
  9. enum KMLoginInputType: Int, CaseIterable {
  10. case apple = 0
  11. case google = 1
  12. }
  13. class KMLoginManager: NSObject {
  14. static let manager = KMLoginManager()
  15. private var loginCompletion: KMLoginCompletion?
  16. }
  17. extension KMLoginManager {
  18. func login(_ inputType: KMLoginInputType, _ completion: @escaping KMLoginCompletion) {
  19. self.loginCompletion = completion
  20. if inputType == .apple {
  21. KMAppleLoginManager.manager.login { [weak self] user, token, error in
  22. if token.count != 0 {
  23. guard let callBack = self?.loginCompletion else { return }
  24. callBack(true, .unknown)
  25. }
  26. }
  27. }
  28. }
  29. }