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

Merge branch 'appleLogin' into youhua-dev

parents bbaabe74 8519d77b
......@@ -247,6 +247,7 @@
049537852BA9B28500AF7E59 /* YHCertificateTemplateCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049537842BA9B28500AF7E59 /* YHCertificateTemplateCell.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 */; };
0499E3042C05B91A0037E646 /* YHAppleLoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0499E3032C05B91A0037E646 /* YHAppleLoginViewController.swift */; };
049A48A82B49417300D0C641 /* YHAboutUsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */; };
049A48AA2B49536000D0C641 /* YHAboutUsAdvantageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A48A92B49536000D0C641 /* YHAboutUsAdvantageCell.swift */; };
049AC4C62BC3E55300F857F4 /* YHServiceSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049AC4C52BC3E55300F857F4 /* YHServiceSectionView.swift */; };
......@@ -287,6 +288,7 @@
04EA376F2BEA071600DBAF64 /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 04EA376E2BEA070500DBAF64 /* libc++.tbd */; };
04EA37742BEA0A3400DBAF64 /* YHShareManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04EA37732BEA0A3400DBAF64 /* YHShareManager.swift */; };
04F4B76B2BAA7E1E00D13284 /* YHCertificateTemplateSheetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04F4B76A2BAA7E1E00D13284 /* YHCertificateTemplateSheetView.swift */; };
04FA8B2B2C06F59D00ABE43F /* YHAppleLoginManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04FA8B2A2C06F59D00ABE43F /* YHAppleLoginManager.swift */; };
6203A87EDC96313BBE789D9C /* Pods_galaxy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 987C69D43AE8D85DC1930DCF /* Pods_galaxy.framework */; };
A51044182B493675006B60BB /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = A51044172B493675006B60BB /* README.md */; };
A510441A2B495DD0006B60BB /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51044192B495DD0006B60BB /* UIView+Extension.swift */; };
......@@ -712,6 +714,7 @@
049537842BA9B28500AF7E59 /* YHCertificateTemplateCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCertificateTemplateCell.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>"; };
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>"; };
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>"; };
......@@ -752,6 +755,7 @@
04EA376E2BEA070500DBAF64 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; };
04EA37732BEA0A3400DBAF64 /* YHShareManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHShareManager.swift; sourceTree = "<group>"; };
04F4B76A2BAA7E1E00D13284 /* YHCertificateTemplateSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCertificateTemplateSheetView.swift; sourceTree = "<group>"; };
04FA8B2A2C06F59D00ABE43F /* YHAppleLoginManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAppleLoginManager.swift; sourceTree = "<group>"; };
19B28612265782F9DC1BE0B0 /* Pods-galaxy.testenv.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-galaxy.testenv.xcconfig"; path = "Target Support Files/Pods-galaxy/Pods-galaxy.testenv.xcconfig"; sourceTree = "<group>"; };
58C2405158A4A6632D0E7460 /* Pods-galaxy.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-galaxy.debug.xcconfig"; path = "Target Support Files/Pods-galaxy/Pods-galaxy.debug.xcconfig"; sourceTree = "<group>"; };
987C69D43AE8D85DC1930DCF /* Pods_galaxy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_galaxy.framework; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -1713,6 +1717,23 @@
path = CustomRefreshHeader;
sourceTree = "<group>";
};
0499E3012C05B73D0037E646 /* AppleLogin(苹果登录) */ = {
isa = PBXGroup;
children = (
0499E3022C05B7E90037E646 /* C */,
);
path = "AppleLogin(苹果登录)";
sourceTree = "<group>";
};
0499E3022C05B7E90037E646 /* C */ = {
isa = PBXGroup;
children = (
0499E3032C05B91A0037E646 /* YHAppleLoginViewController.swift */,
04FA8B2A2C06F59D00ABE43F /* YHAppleLoginManager.swift */,
);
path = C;
sourceTree = "<group>";
};
04A671562B9F18C800C1FB91 /* MyCertificates(我的证书) */ = {
isa = PBXGroup;
children = (
......@@ -2323,6 +2344,7 @@
A5ACE91B2B4564F7002C94D2 /* Modules */ = {
isa = PBXGroup;
children = (
0499E3012C05B73D0037E646 /* AppleLogin(苹果登录) */,
0445E6AC2BE9CF53003C52F9 /* VersionUpload(版本更新) */,
A567E5662BD7643D00D5D5A0 /* Home(首页) */,
04174D652BCD5B74000BA46D /* Message(消息) */,
......@@ -2958,6 +2980,7 @@
A517A4E12BB573EB000DEECD /* YHDocListCell.swift in Sources */,
A58037212BAD7B2A0031C312 /* YHMySchemeModel.swift in Sources */,
0493B3DE2BA80C2300AF9393 /* YHCertificateFilterButton.swift in Sources */,
04FA8B2B2C06F59D00ABE43F /* YHAppleLoginManager.swift in Sources */,
A567E5932BD7643D00D5D5A0 /* YHHomePageViewModel.swift in Sources */,
045EEE822B9F171A0022A143 /* YHPersonInfoIdentityCardModel.swift in Sources */,
045EEE952B9F171A0022A143 /* YHPreviewInfoCertificateInformationItemsView.swift in Sources */,
......@@ -2995,6 +3018,7 @@
045EEF092B9F171A0022A143 /* YHBasicInfoFillModel.swift in Sources */,
A5ACE9352B4564F7002C94D2 /* YHNetRequest.swift in Sources */,
A5FD63CB2B63D6C300D1D9DA /* YHInformationFillTipsCell.swift in Sources */,
0499E3042C05B91A0037E646 /* YHAppleLoginViewController.swift in Sources */,
045EEF1F2B9F171A0022A143 /* YHDatePickView.swift in Sources */,
04174D7A2BCD5B74000BA46D /* YHDetailMessageCell.swift in Sources */,
045EEE972B9F171A0022A143 /* YHPreviewInfoWorkExpView.swift in Sources */,
......
......@@ -7,6 +7,7 @@
//
import UIKit
import AuthenticationServices
extension AppDelegate: JPUSHRegisterDelegate {
......@@ -133,3 +134,37 @@ extension AppDelegate: JPUSHRegisterDelegate {
}
}
extension AppDelegate {
func handleAppleLoginUser() {
if #available(iOS 13.0, *) {
// 注意 存储用户标识信息需要使用钥匙串来存储 这里使用NSUserDefaults 做的简单示例
let userIdentifier = UserDefaults.standard.value(forKey: "appleID") as? String
if let userIdentifier = userIdentifier {
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: userIdentifier) {
credentialState, error in
switch credentialState {
case .authorized:
// 授权状态有效
break
case .revoked:
// 苹果账号登录的凭据已被移除,需解除绑定并重新引导用户使用苹果登录
break
case .notFound:
// 未登录授权,直接弹出登录页面,引导用户登录
break
case .transferred:
// 授权AppleID提供者凭据转移
break
default:
break
}
}
}
}
}
}
//
// YHAppleLoginManager.swift
// galaxy
//
// Created by edy on 2024/5/29.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import AuthenticationServices
class YHAppleLoginManager: NSObject {
func appleLogin() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
let vc = ASAuthorizationController(authorizationRequests: [request])
vc.delegate = self
vc.presentationContextProvider = self
vc.performRequests()
}
}
extension YHAppleLoginManager: 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()!
}
}
//
// 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()!
}
}
......@@ -268,6 +268,12 @@ extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
if (indexPath.row >= items.count) { return }
if true {
let vc = YHAppleLoginViewController()
self.navigationController?.pushViewController(vc)
return
}
//#if DEBUG
// let vc = YHCodeSueecssWithVideoBkgViewController()
// vc.phoneNumber = "15818743775"
......
......@@ -4,6 +4,10 @@
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
<key>com.apple.developer.associated-domains</key>
<array>
<string>webcredentials:www.galaxy-immi.com</string>
......
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