Commit 523096a4 authored by Steven杜宇's avatar Steven杜宇

一键登录

parent b88bc567
......@@ -54,7 +54,8 @@ extension YHAppleLoginManager: ASAuthorizationControllerDelegate, ASAuthorizatio
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
printLog("FAILED: \(error.localizedDescription)")
YHHUD.flash(message: "苹果登录失败 原因:\(error.localizedDescription)")
printLog("Apple login FAILED: \(error.localizedDescription)")
}
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
......
......@@ -12,21 +12,19 @@ import AVFoundation
class YHOneKeyLoginManager {
static let shared = YHOneKeyLoginManager()
// 是否加速取号成功
var isAccelerateGetPhontNumberSuccess = false
}
extension YHOneKeyLoginManager {
func oneKeyLogin() {
YHOneKeyLoginManager.shared.checkIsSupportOneKeyLogin {
support in
if !support {
YHHUD.flash(message: "不支持一键登录")
// 跳转APP自定义登录界面
let vc = UINavigationController(rootVC: YHOtherLoginViewController())
vc.modalPresentationStyle = .fullScreen
UIViewController.current?.present(vc, animated: true)
self.enterAppLoginPage(isFromOneKeyPage: false)
return
}
// 支持一键登录
......@@ -34,6 +32,19 @@ extension YHOneKeyLoginManager {
}
}
// 进入App自己设计的主登录界面
// @param isFromOneKeyPage:是否是从一键登录界面进入
func enterAppLoginPage(isFromOneKeyPage:Bool) {
if isFromOneKeyPage {
let vc = YHOtherLoginViewController()
UIViewController.current?.navigationController?.pushViewController(vc, animated:true)
return
}
let vc = UINavigationController(rootVC: YHOtherLoginViewController())
vc.modalPresentationStyle = .fullScreen
UIViewController.current?.present(vc, animated: true)
}
func getSDKVersion() -> String {
return TXCommonHandler.sharedInstance().getVersion()
}
......@@ -42,27 +53,13 @@ extension YHOneKeyLoginManager {
TXCommonHandler.sharedInstance().setAuthSDKInfo(YhConstant.Alipay.kAliLoginSecretKey) {
dict in
printLog(dict)
}
printLog("设置secretKey结果:\(dict)")
// 进行加速登录 方便点击登录时提速
TXCommonHandler.sharedInstance().accelerateLoginPage(withTimeout: 10.0) {
dic in
guard let code = dic["resultCode"] as? String else {
printLog("加速取号失败")
YHOneKeyLoginManager.shared.isAccelerateGetPhontNumberSuccess = false
return
}
if code != PNSCodeSuccess {
printLog("加速取号失败")
YHOneKeyLoginManager.shared.isAccelerateGetPhontNumberSuccess = false
return
printLog("加速登录结果: \(dic)")
}
// 加速取号成功
printLog("加速取号成功")
YHOneKeyLoginManager.shared.isAccelerateGetPhontNumberSuccess = true
}
}
......@@ -71,6 +68,8 @@ extension YHOneKeyLoginManager {
TXCommonHandler.sharedInstance().checkEnvAvailable(with: .loginToken) {
dict in
printLog("checkEnvAvailable: \(String(describing: dict))")
if let resultCode = dict?["resultCode"] as? String, resultCode == PNSCodeSuccess {
support?(true)
} else {
......@@ -84,9 +83,15 @@ extension YHOneKeyLoginManager {
// 3. 开始一键登录流程
//3.2 调用获取登录Token接口,可以立马弹起授权页,model的创建需要放在主线程
let model = self.createLoginUIModel()
TXCommonHandler.sharedInstance().getLoginToken(withTimeout: 10.0, controller: UIViewController.current!, model: model) {
YHHUD.show(.progress(message: "加载中..."))
TXCommonHandler.sharedInstance().getLoginToken(withTimeout: 3.0, controller: UIViewController.current!, model: model) {
dict in
DispatchQueue.main.async {
YHHUD.hide()
}
guard let code = dict["resultCode"] as? String else {
printLog(dict)
return
......@@ -94,8 +99,9 @@ extension YHOneKeyLoginManager {
if code == PNSCodeSuccess {
// 点击登录按钮获取登录Token成功回调
guard let token = dict["token"] as? String else {
guard let token = dict["token"] as? String, !token.isEmpty else {
printLog("获取登录Token失败")
return
}
printLog("oneKeyLogin token: \(token)")
......@@ -124,9 +130,17 @@ extension YHOneKeyLoginManager {
// 以下是处理一键登录异常
if code == PNSCodeLoginControllerPresentSuccess {
if code == PNSCodeLoginControllerPresentFailed {
printLog("弹起授权页失败")
// 此时一键登录界面未显示
self.enterAppLoginPage(isFromOneKeyPage: true)
} else if code == PNSCodeLoginControllerPresentSuccess {
printLog("弹起授权页成功")
} else if code == PNSCodeCallPreLoginInAuthPage {
printLog("授权页已加载时不允许调用加速或预取号接口")
} else if code == PNSCodeLoginControllerClickCancel {
printLog("点击了授权页的返回")
......@@ -147,12 +161,28 @@ extension YHOneKeyLoginManager {
} else if code == PNSCodeLoginControllerClickProtocol {
printLog("点击了协议富文本")
} else if code == PNSCodeLoginClickPrivacyAlertView {
printLog("点击一键登录拉起授权页二次弹窗")
} else if code == PNSCodeLoginPrivacyAlertViewClose {
printLog("点击隐私协议二次弹窗关闭")
} else if code == PNSCodeLoginPrivacyAlertViewClickContinue {
printLog("隐私协议二次弹窗点击确认并继续")
} else if code == PNSCodeLoginPrivacyAlertViewPrivacyContentClick {
printLog("点击隐私协议二次弹窗上的协议富文本文字")
} else if code == PNSCodeLoginControllerSuspendDisMissVC {
printLog("中断页面消失的时候,也就是suspendDisMissVC设置为YES的时候")
} else {
printLog("其他错误:\(dict)")
self.enterAppLoginPage(isFromOneKeyPage: true)
}
}
}
func createLoginUIModel() -> TXCustomModel {
let model = TXCustomModel()
......@@ -212,9 +242,11 @@ extension YHOneKeyLoginManager {
}
// 改变登录方式
videoBgView.changeLoginBlock = {
let vc = YHOtherLoginViewController()
UIViewController.current?.navigationController?.pushViewController(vc, animated:true)
[weak self] in
guard let self = self else { return }
self.enterAppLoginPage(isFromOneKeyPage: true)
}
model.customViewBlock = {
superCustomView in
superCustomView.insertSubview(videoBgView, at: 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment