Commit b404779f authored by Steven杜宇's avatar Steven杜宇

// Apple 登录

parent 29663b1c
...@@ -247,7 +247,6 @@ ...@@ -247,7 +247,6 @@
049663BA2BF6105C003C8295 /* YHRefreshHeaderAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049663B92BF6105C003C8295 /* YHRefreshHeaderAnimator.swift */; }; 049663BA2BF6105C003C8295 /* YHRefreshHeaderAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049663B92BF6105C003C8295 /* YHRefreshHeaderAnimator.swift */; };
049663C02BF729F6003C8295 /* galaxy_refresher.gif in Resources */ = {isa = PBXBuildFile; fileRef = 049663BF2BF729F5003C8295 /* galaxy_refresher.gif */; }; 049663C02BF729F6003C8295 /* galaxy_refresher.gif in Resources */ = {isa = PBXBuildFile; fileRef = 049663BF2BF729F5003C8295 /* galaxy_refresher.gif */; };
0499E3002C056EE30037E646 /* YHOneKeyLoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0499E2FF2C056EE30037E646 /* YHOneKeyLoginView.swift */; }; 0499E3002C056EE30037E646 /* YHOneKeyLoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0499E2FF2C056EE30037E646 /* YHOneKeyLoginView.swift */; };
0499E3042C05B91A0037E646 /* YHAppleLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0499E3032C05B91A0037E646 /* YHAppleLoginViewController.swift */; };
049A48A82B49417300D0C641 /* YHAboutUsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */; }; 049A48A82B49417300D0C641 /* YHAboutUsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */; };
049A48AA2B49536000D0C641 /* YHAboutUsAdvantageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A48A92B49536000D0C641 /* YHAboutUsAdvantageCell.swift */; }; 049A48AA2B49536000D0C641 /* YHAboutUsAdvantageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A48A92B49536000D0C641 /* YHAboutUsAdvantageCell.swift */; };
049AC4C62BC3E55300F857F4 /* YHServiceSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049AC4C52BC3E55300F857F4 /* YHServiceSectionView.swift */; }; 049AC4C62BC3E55300F857F4 /* YHServiceSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049AC4C52BC3E55300F857F4 /* YHServiceSectionView.swift */; };
...@@ -721,7 +720,6 @@ ...@@ -721,7 +720,6 @@
049663B92BF6105C003C8295 /* YHRefreshHeaderAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHRefreshHeaderAnimator.swift; sourceTree = "<group>"; }; 049663B92BF6105C003C8295 /* YHRefreshHeaderAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHRefreshHeaderAnimator.swift; sourceTree = "<group>"; };
049663BF2BF729F5003C8295 /* galaxy_refresher.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = galaxy_refresher.gif; sourceTree = "<group>"; }; 049663BF2BF729F5003C8295 /* galaxy_refresher.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = galaxy_refresher.gif; sourceTree = "<group>"; };
0499E2FF2C056EE30037E646 /* YHOneKeyLoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHOneKeyLoginView.swift; sourceTree = "<group>"; }; 0499E2FF2C056EE30037E646 /* YHOneKeyLoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHOneKeyLoginView.swift; sourceTree = "<group>"; };
0499E3032C05B91A0037E646 /* YHAppleLoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAppleLoginViewController.swift; sourceTree = "<group>"; };
049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAboutUsViewController.swift; sourceTree = "<group>"; }; 049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAboutUsViewController.swift; sourceTree = "<group>"; };
049A48A92B49536000D0C641 /* YHAboutUsAdvantageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAboutUsAdvantageCell.swift; sourceTree = "<group>"; }; 049A48A92B49536000D0C641 /* YHAboutUsAdvantageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAboutUsAdvantageCell.swift; sourceTree = "<group>"; };
049AC4C52BC3E55300F857F4 /* YHServiceSectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHServiceSectionView.swift; sourceTree = "<group>"; }; 049AC4C52BC3E55300F857F4 /* YHServiceSectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHServiceSectionView.swift; sourceTree = "<group>"; };
...@@ -1742,18 +1740,17 @@ ...@@ -1742,18 +1740,17 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
04FA8B312C08808B00ABE43F /* V */, 04FA8B312C08808B00ABE43F /* V */,
0499E3022C05B7E90037E646 /* C */, 0499E3022C05B7E90037E646 /* M */,
); );
path = "AppleLogin(苹果登录)"; path = "AppleLogin(苹果登录)";
sourceTree = "<group>"; sourceTree = "<group>";
}; };
0499E3022C05B7E90037E646 /* C */ = { 0499E3022C05B7E90037E646 /* M */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
0499E3032C05B91A0037E646 /* YHAppleLoginViewController.swift */,
04FA8B2A2C06F59D00ABE43F /* YHAppleLoginManager.swift */, 04FA8B2A2C06F59D00ABE43F /* YHAppleLoginManager.swift */,
); );
path = C; path = M;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
04A671562B9F18C800C1FB91 /* MyCertificates(我的证书) */ = { 04A671562B9F18C800C1FB91 /* MyCertificates(我的证书) */ = {
...@@ -3080,7 +3077,6 @@ ...@@ -3080,7 +3077,6 @@
045EEF092B9F171A0022A143 /* YHBasicInfoFillModel.swift in Sources */, 045EEF092B9F171A0022A143 /* YHBasicInfoFillModel.swift in Sources */,
A5ACE9352B4564F7002C94D2 /* YHNetRequest.swift in Sources */, A5ACE9352B4564F7002C94D2 /* YHNetRequest.swift in Sources */,
A5FD63CB2B63D6C300D1D9DA /* YHInformationFillTipsCell.swift in Sources */, A5FD63CB2B63D6C300D1D9DA /* YHInformationFillTipsCell.swift in Sources */,
0499E3042C05B91A0037E646 /* YHAppleLoginViewController.swift in Sources */,
045EEF1F2B9F171A0022A143 /* YHDatePickView.swift in Sources */, 045EEF1F2B9F171A0022A143 /* YHDatePickView.swift in Sources */,
04174D7A2BCD5B74000BA46D /* YHDetailMessageCell.swift in Sources */, 04174D7A2BCD5B74000BA46D /* YHDetailMessageCell.swift in Sources */,
045EEE972B9F171A0022A143 /* YHPreviewInfoWorkExpView.swift in Sources */, 045EEE972B9F171A0022A143 /* YHPreviewInfoWorkExpView.swift in Sources */,
......
//
// YHAppleLoginViewController.swift
// galaxy
//
// Created by edy on 2024/5/28.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import AuthenticationServices
class YHAppleLoginViewController: YHBaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
func setupUI() {
let appleLoginBtn: ASAuthorizationAppleIDButton = ASAuthorizationAppleIDButton.init(authorizationButtonType: .default, authorizationButtonStyle: .white)
appleLoginBtn.frame = CGRectMake(50, 200, KScreenWidth-100, 45)
self.view.addSubview(appleLoginBtn)
appleLoginBtn.addTarget(self, action: #selector(didAppleIDBtnClicked), for: .touchUpInside)
view.addSubview(appleLoginBtn)
}
@objc func didAppleIDBtnClicked() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
// let keychainRequest = ASAuthorizationPasswordProvider().createRequest()
let vc = ASAuthorizationController(authorizationRequests: [request])
vc.delegate = self
vc.presentationContextProvider = self
vc.performRequests()
}
}
extension YHAppleLoginViewController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
// 其中`authorization.credential`包含了Token,用户ID等授权所需信息,可上报到后台
let credential = authorization.credential
if credential is ASPasswordCredential {
let passwdCredential = credential as! ASPasswordCredential
let userIdentifier = passwdCredential.user
let username = passwdCredential.user
let password = passwdCredential.password
printLog("username:\(username), passwd:\(password)")
} else if credential is ASAuthorizationAppleIDCredential {
let appleIdCredential = credential as! ASAuthorizationAppleIDCredential
let userIdentifier = appleIdCredential.user
let fullName = appleIdCredential.fullName
let email = appleIdCredential.email ?? "email"
let authorizationCode = appleIdCredential.authorizationCode
let authorizationCodeStr = String(decoding: authorizationCode!, as: UTF8.self)
let identityToken = appleIdCredential.identityToken
let identityTokenStr = String(decoding: identityToken!, as: UTF8.self)
let realUserStatus = appleIdCredential.realUserStatus
printLog("authorizationCodeStr: \(authorizationCodeStr)")
}
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
printLog("FAILED: \(error.localizedDescription)")
}
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return UIApplication.shared.yhKeyWindow()!
}
}
...@@ -38,7 +38,6 @@ extension YHAppleLoginManager: ASAuthorizationControllerDelegate, ASAuthorizatio ...@@ -38,7 +38,6 @@ extension YHAppleLoginManager: ASAuthorizationControllerDelegate, ASAuthorizatio
var authorizationCodeStr = "" var authorizationCodeStr = ""
var identityTokenStr = "" var identityTokenStr = ""
// 其中`authorization.credential`包含了Token,用户ID等授权所需信息,可上报到后台
let credential = authorization.credential let credential = authorization.credential
if credential is ASPasswordCredential { if credential is ASPasswordCredential {
let passwdCredential = credential as! ASPasswordCredential let passwdCredential = credential as! ASPasswordCredential
...@@ -51,6 +50,7 @@ extension YHAppleLoginManager: ASAuthorizationControllerDelegate, ASAuthorizatio ...@@ -51,6 +50,7 @@ extension YHAppleLoginManager: ASAuthorizationControllerDelegate, ASAuthorizatio
let appleIdCredential = credential as! ASAuthorizationAppleIDCredential let appleIdCredential = credential as! ASAuthorizationAppleIDCredential
userId = appleIdCredential.user userId = appleIdCredential.user
email = appleIdCredential.email ?? "" email = appleIdCredential.email ?? ""
fullName = appleIdCredential.fullName?.givenName ?? ""
let authorizationCode = appleIdCredential.authorizationCode let authorizationCode = appleIdCredential.authorizationCode
authorizationCodeStr = String(decoding: authorizationCode!, as: UTF8.self) authorizationCodeStr = String(decoding: authorizationCode!, as: UTF8.self)
let identityToken = appleIdCredential.identityToken let identityToken = appleIdCredential.identityToken
...@@ -62,13 +62,13 @@ extension YHAppleLoginManager: ASAuthorizationControllerDelegate, ASAuthorizatio ...@@ -62,13 +62,13 @@ extension YHAppleLoginManager: ASAuthorizationControllerDelegate, ASAuthorizatio
printLog("APPLE LOGIN identityToken:\(identityTokenStr)") printLog("APPLE LOGIN identityToken:\(identityTokenStr)")
printLog("APPLE LOGIN authorizationCode: \(authorizationCodeStr)") printLog("APPLE LOGIN authorizationCode: \(authorizationCodeStr)")
let params:[String: Any] = ["apple_id": "string", let params:[String: Any] = ["full_name": fullName,
"user_id": userId, "user_id": userId,
"email": "string", "email": email,
"full_name": "string",
"authorization_code": authorizationCodeStr, "authorization_code": authorizationCodeStr,
"identity_token": identityTokenStr] "identity_token": identityTokenStr]
self.success?(params) self.success?(params)
} }
......
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