티스토리 뷰
Why ?
- 소셜로그인을 구현하면 애플 로그인도 있어야 스토어 심사에서 리젝당하지 않는다.
- SwiftUI로 애플 로그인을 구현해보지 못해서 공부해본다.
How ?
Capabilities 추가
Capabilities에 Sign in with Apple 추가
근데 혹시 ADP를 결제해야 사용할 수 있다는 것을 나만 몰랐나..?
돈 안내고쓰면 애플로그인도 안시켜줘… 관련 자료를 레퍼런스에 첨부해놔야겠다..
로그인
import AuthenticationServices
func loginWithApple() {
let request = ASAuthorizationAppleIDProvider().createRequest()
request.requestedScopes = [.fullName, .email]
let controller = ASAuthorizationController(authorizationRequests: [request])
controller.delegate = self
controller.performRequests()
}
로그인 함수 구현
버튼
Button {
viewModel.loginWithApple()
} label: {
Text("애플 로그인")
.frame(height: 50)
.foregroundColor(.white)
.frame(minWidth: .zero, maxWidth: .infinity)
.background(Color.black)
.cornerRadius(8)
.padding(.leading, 16)
.padding(.trailing, 16)
}
애플로그인 화면 띄우는 버튼 생성
델리게이트
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
if let credential = authorization.credential as? ASAuthorizationAppleIDCredential {
let userIdentifier = credential.user
let fullName = credential.fullName
let email = credential.email
print(userIdentifier, fullName, email, separator: "\\n")
}
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
print("Fail")
}
로그인 완료되었을 때 처리
상태 확인
func checkAppleLogin() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: userIdentifier) { (credentialState, error) in
switch credentialState {
case .authorized:
//인증성공 상태
print("authorized")
case .revoked:
//인증만료 상태
print("revoked")
default:
//.notFound 등 이외 상태
print("?")
}
}
}
변하지 않는 userIdentifier로 인증상태 체크
🤔
한번 로그인하고 나면은 앱을 지웠다 깔아도 처음에 회원가입처럼 되지않고 로그인이 된다고 한다!
애플에서 지원하는 만큼 찾아보면 찾아볼수록 더욱 많은 기능이 있는 것 같았다.
앱을 사용중인데 Apple ID 연결을 해제 했을 때의 상황도 체크를 해줘야 하는 것 같았고, 로그인을 하고 나서 키체인에 저장하는 방식도 있었다.
간단하게 애플로그인을 공부해봤는데 상황에 맞게 좀 더 추가되는 부분이 있을 것 같다.
Reference
https://help.apple.com/developer-account/#/dev21218dfd6
To see this page, you must enable JavaScript. Pour afficher cette page, vous devez activer JavaScript. Zur Anzeige dieser Seite müssen Sie JavaScript aktivieren. このページを表示するには、JavaScript を有効にする必要があります。
help.apple.com
iOS ) Sign in with Apple (2)
안녕하세요 :) Zedd입니다. Sign In with Apple 2탄..!!! 공부해봅시당. Sign in with Apple Sign In with Apple (1)에서 딱 이거까지 띄우고 끝났는데요, 이제 진짜 로그인 해봅시댜 저번ㅇㅔ 채택해준 이 친..
zeddios.tistory.com
'iOS > SwiftUI' 카테고리의 다른 글
[SwiftUI] 코드로 네비게이션 실행하기 (0) | 2022.07.20 |
---|---|
[SwiftUI] @ObservedObject, @StateObject (0) | 2022.07.07 |
[SwiftUI] 카카오 로그인 (0) | 2022.06.15 |
[SwiftUI] Splash (0) | 2022.06.15 |
[SwiftUI] Custom navigation back button (0) | 2022.05.30 |
- Total
- Today
- Yesterday
- onTapGesture
- 곰튀김
- MVVM
- delegate
- Login
- frame과 bounds 차이
- strcut
- enumerations
- SwiftUI
- Git
- Xcode
- ObservedObject
- file private
- AWS
- Swift
- AWS Fargate
- Generic
- kakao
- Protocol
- CodingTest
- OCR
- Custom
- 의미있는이름
- docker
- tabview
- navigation
- rxswift
- IOS
- ChatGPT
- 카메라
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |