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

65 lines
2.0 KiB
Swift
Raw Normal View History

2021-12-27 22:33:27 +08:00
//
// 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()
2022-01-04 22:28:18 +08:00
AppleSignInButton(
2021-12-27 22:33:27 +08:00
onRequest: { request in
2022-01-04 22:28:18 +08:00
request.requestedScopes = [.fullName, .email]
2021-12-27 22:33:27 +08:00
},
onCompletion: { result in
2022-01-04 22:28:18 +08:00
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)
}
2021-12-27 22:33:27 +08:00
}
)
2022-01-04 22:28:18 +08:00
.frame(maxWidth: 375, minHeight: 64, maxHeight: 64)
2021-12-27 22:33:27 +08:00
.padding()
Spacer()
}
.padding()
}
}
struct LoginView_Previews: PreviewProvider {
static var previews: some View {
LoginView()
}
}