|
|
@@ -44,6 +44,22 @@ extension LNLoginPanel: LNAccountManagerNotify {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+extension LNLoginPanel: ASAuthorizationControllerDelegate {
|
|
|
+ func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
|
|
|
+ guard let credential = authorization.credential as? ASAuthorizationAppleIDCredential,
|
|
|
+ let token = credential.identityToken,
|
|
|
+ let tokenStr = String(data: token, encoding: .utf8)
|
|
|
+ else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ LNAccountManager.shared.loginByApple(data: tokenStr)
|
|
|
+ }
|
|
|
+
|
|
|
+ func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: any Error) {
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
extension LNLoginPanel {
|
|
|
private func setupViews() {
|
|
|
container.backgroundColor = .text_5.withAlphaComponent(0.7)
|
|
|
@@ -69,22 +85,20 @@ extension LNLoginPanel {
|
|
|
stackView.spacing = 16
|
|
|
container.addSubview(stackView)
|
|
|
stackView.snp.makeConstraints { make in
|
|
|
- make.directionalHorizontalEdges.equalToSuperview().inset(38)
|
|
|
+ make.horizontalEdges.equalToSuperview().inset(38)
|
|
|
make.bottom.equalTo(privacy.snp.top).offset(-50)
|
|
|
}
|
|
|
|
|
|
- var logins: [UIView] = []
|
|
|
#if DEBUG
|
|
|
let email = buildEmail()
|
|
|
- logins.append(email)
|
|
|
+ stackView.addArrangedSubview(email)
|
|
|
#endif
|
|
|
|
|
|
- let google = buildGoogleLogin()
|
|
|
- logins.append(google)
|
|
|
+ let apple = buildAppleLogin()
|
|
|
+ stackView.addArrangedSubview(apple)
|
|
|
|
|
|
- logins.forEach {
|
|
|
- stackView.addArrangedSubview($0)
|
|
|
- }
|
|
|
+ let google = buildGoogleLogin()
|
|
|
+ stackView.addArrangedSubview(google)
|
|
|
|
|
|
let tipsLabel = UILabel()
|
|
|
tipsLabel.text = .init(key: "A00114")
|
|
|
@@ -94,7 +108,7 @@ extension LNLoginPanel {
|
|
|
tipsLabel.textAlignment = .center
|
|
|
container.addSubview(tipsLabel)
|
|
|
tipsLabel.snp.makeConstraints { make in
|
|
|
- make.directionalHorizontalEdges.equalToSuperview().inset(38)
|
|
|
+ make.horizontalEdges.equalToSuperview().inset(38)
|
|
|
make.bottom.equalTo(stackView.snp.top).offset(-16)
|
|
|
}
|
|
|
|
|
|
@@ -106,6 +120,45 @@ extension LNLoginPanel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private func buildAppleLogin() -> UIView {
|
|
|
+ let button = UIButton()
|
|
|
+ button.backgroundColor = .init(hex: "#0B0B0A")
|
|
|
+ button.layer.cornerRadius = 24
|
|
|
+ button.snp.makeConstraints { make in
|
|
|
+ make.height.equalTo(48)
|
|
|
+ }
|
|
|
+
|
|
|
+ let ic = UIImageView()
|
|
|
+ ic.image = .init(named: "ic_apple")
|
|
|
+ button.addSubview(ic)
|
|
|
+ ic.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.leading.equalToSuperview().offset(12)
|
|
|
+ }
|
|
|
+
|
|
|
+ let title = UILabel()
|
|
|
+ title.font = .heading_h3
|
|
|
+ title.textColor = .text_1
|
|
|
+ title.text = .init(key: "A00285")
|
|
|
+ button.addSubview(title)
|
|
|
+ title.snp.makeConstraints { make in
|
|
|
+ make.center.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ button.addAction(UIAction(handler: { [weak self] _ in
|
|
|
+ guard let self else { return }
|
|
|
+ let provider = ASAuthorizationAppleIDProvider()
|
|
|
+ let request = provider.createRequest()
|
|
|
+ request.requestedScopes = [.fullName, .email]
|
|
|
+ let controller = ASAuthorizationController(authorizationRequests: [request])
|
|
|
+ controller.delegate = self
|
|
|
+// controller.presentationContextProvider = self
|
|
|
+ controller.performRequests()
|
|
|
+ }), for: .touchUpInside)
|
|
|
+
|
|
|
+ return button
|
|
|
+ }
|
|
|
+
|
|
|
private func buildGoogleLogin() -> UIView {
|
|
|
let button = UIButton()
|
|
|
button.backgroundColor = .fill
|
|
|
@@ -220,6 +273,7 @@ extension LNLoginPanel {
|
|
|
#if DEBUG
|
|
|
|
|
|
import SwiftUI
|
|
|
+import AuthenticationServices
|
|
|
|
|
|
struct LNLoginPanelPreview: UIViewRepresentable {
|
|
|
func makeUIView(context: Context) -> some UIView {
|