71 lines
2.3 KiB
Swift
71 lines
2.3 KiB
Swift
//
|
|
// SPLoginManager+Apple.swift
|
|
// Thimra
|
|
//
|
|
// Created by 佳尔 on 2025/4/25.
|
|
//
|
|
|
|
import UIKit
|
|
import AuthenticationServices
|
|
|
|
|
|
extension SPLoginManager {
|
|
|
|
///苹果登录
|
|
func appleSignLogin(completer: ((_ model: SPThirdSignModel?) -> Void)?) {
|
|
// self.signAppleHandle = completer
|
|
|
|
let appleIDProvider = ASAuthorizationAppleIDProvider()
|
|
let request = appleIDProvider.createRequest()
|
|
request.requestedScopes = [.fullName, .email]
|
|
|
|
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
|
|
authorizationController.delegate = self
|
|
authorizationController.presentationContextProvider = self
|
|
authorizationController.performRequests()
|
|
}
|
|
}
|
|
|
|
//MARK:-------------- ASAuthorizationControllerDelegate --------------
|
|
extension SPLoginManager: ASAuthorizationControllerDelegate {
|
|
|
|
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
|
|
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
|
|
|
|
let userIdentifier = appleIDCredential.user
|
|
let fullName = appleIDCredential.fullName
|
|
let email = appleIDCredential.email
|
|
|
|
let model = SPThirdSignModel()
|
|
model.userID = userIdentifier
|
|
model.givenName = fullName?.givenName
|
|
model.familyName = fullName?.familyName
|
|
model.name = fullName?.nickname
|
|
model.email = email
|
|
|
|
spLog(message: userIdentifier)
|
|
spLog(message: fullName)
|
|
spLog(message: email)
|
|
|
|
// if let signAppleHandle = signAppleHandle {
|
|
// signAppleHandle(model)
|
|
// }
|
|
}
|
|
}
|
|
|
|
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
|
|
// if let signAppleHandle = signAppleHandle {
|
|
// signAppleHandle(nil)
|
|
// }
|
|
}
|
|
|
|
}
|
|
|
|
extension SPLoginManager: ASAuthorizationControllerPresentationContextProviding {
|
|
|
|
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
|
|
return SPAPPTool.getKeyWindow()!
|
|
}
|
|
|
|
}
|