- Total
꿈꾸는리버리
[iOS] Sign In with Apple 구현하기 본문
iOS 앱에서는 필수로 들어가는 소셜 로그인을 구현한다면, 애플로그인을 반드시 구현해야 한다고 한다. ( apple 심사 지침 참고 )
🔮 코드 구현
1️⃣ capability 추가하기
XCode Project > Signing & Capabilities > + Capability > Sign In with Apple을 검색 후 추가!
2️⃣ AuthenticationServices
Apple 로그인을 사용하기 위한 프레임워크인 AuthenticationServices을 추가해준다.
import AuthenticationServices
3️⃣ 코드 구현
애플 ... 너는 계획이 다.. 있구나?
SignInWithAppleButton 을 활용하면 로그인을 쉽게 구현할 수 있다.
SignInWithAppleButton | Apple Developer Documentation
The view that creates the Sign in with Apple button for display.
developer.apple.com
- SignInWithAppleButton
SignInWithAppleButton에는 Button안에 들어가는 Label을 지정할 수 있다.
- OnRequest
onRequest.requestedScopes에 필요한 유저의 정보를 넣는다.
request.requestedScopes = [.email, .fullName]
- OnCompletion
성공할 시에 auth.credential에서 요구했던 정보 + userID를 발급받을 수 있는데,
userID는 앱을 지웠다 깔아도 똑같이 제공이 되지만, 요구했던 정보는 한번 제공된 이후에 다시 제공해주지 않는다.
따라서 처음에 정보를 다른 곳에 저장해둬야 한다!
switch result {
case .success(let auth):
switch auth.credential {
case let credential as ASAuthorizationAppleIDCredential:
let userID = credential.user
let email = credential.email
let firstName = credential.fullName?.givenName
let lastName = credential.fullName?.familyName
/// Do something to save user info...
default:
break
}
case .failure(let error):
/// Do something to handle error
}
🔮 시뮬레이터로 확인하기
프리뷰에서는 확인할 수 없고 시뮬레이터로 잘 작동되고 있는지 확인할 수 있다.
기기의 Setting에서 우선 Apple ID 로그인을 해야지 확인이
가능하고, 비밀번호를 입력하면 success로 상태가 넘어간다.
'오뚝이 개발자 > SwiftUI' 카테고리의 다른 글
[SwiftUI] View Modifier에서 분기처리하기 (0) | 2024.02.02 |
---|---|
[Swift Concurrency 1] 에러처리 try-catch문 / Result (1) | 2024.02.02 |
SwiftUI에서 modifier 분기 처리하기 (0) | 2022.09.16 |
SwiftUI Widget 딱대(짐).. : localization 적용 (2) | 2022.09.15 |
SwiftUI Widget 딱대(짐).. : 위젯 memory 제한 (2) | 2022.09.15 |