pushdeer/ios/PushDeer-iOS/PushDeer/View/LoginView.swift

65 lines
2.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LoginView.swift
// PushDeer
//
// Created by HEXT on 2021/12/25.
//
import SwiftUI
import AuthenticationServices
///
struct LoginView: View {
var body: some View {
VStack{
Spacer()
Image("logo.with.space")
.resizable()
.scaledToFit()
Spacer()
AppleSignInButton(
onRequest: { request in
request.requestedScopes = [.fullName, .email]
},
onCompletion: { result in
switch result {
case let .success(authorization):
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
// IDAPP
print(appleIDCredential.user) // 000791.7a323f1326dd4674bc16d32fd6339875.1424
// emailfullName->Apple ID->->使AppleIDApp APP
print(appleIDCredential.email as Any) // easychen@qq.com
print(appleIDCredential.fullName as Any) // givenName: lijie familyName: chen
// JWTtoken.3, base64
let idToken = String(data:appleIDCredential.identityToken!, encoding: .utf8)
print(idToken as Any)
Task {
do {
let result = try await HttpRequest.login(idToken: idToken!)
print(result)
} catch {
print(error)
}
}
}
case let .failure(error):
print(error)
}
}
)
.frame(maxWidth: 375, minHeight: 64, maxHeight: 64)
.padding()
Spacer()
}
.padding()
}
}
struct LoginView_Previews: PreviewProvider {
static var previews: some View {
LoginView()
}
}