SwiftUI 프로젝트에 Apple로 로그인을 추가하는 방법
가장 먼저 해야 할 일은 Xcode 왼쪽의 탐색기 상단에 있는 프로젝트 파일로 이동하는 것입니다. 그런 다음 서명 및 기능 탭으로 이동해야 합니다. 이 탭의 왼쪽 모서리에서 + Capability 버튼을 클릭하고 Sign in with Apple을 입력해야 합니다. 그런 다음 Enter 키를 눌러 프로젝트에 추가합니다.

이제 ContentView.swift 파일로 이동하여 시작하겠습니다.
프로젝트에 대한 Apple 버튼으로 로그인하려면 라이브러리를 열어야 합니다. 키보드 단축키 Command + Shift + L을 사용하여 라이브러리를 불러올 수 있습니다. 검색 창에 Sign in with Apple을 입력하고 Sign in with Apple 버튼을 코드나 캔버스에 끌어다 놓을 수 있습니다.

이제 Xcode가 우리 범위에서 Apple로 로그인을 찾을 수 없다는 오류 팝업이 나타날 수 있습니다. 이 오류를 제거하기 위해 해야 할 일은 ContentView.swift 파일의 맨 위에 있는 Import AuthenticationServices입니다. 이제 아래 예제의 코드를 프로젝트에 추가하고 앱에서 구현하는 내용을 살펴보겠습니다.
import SwiftUI import AuthenticationServices struct ContentView: View { var body: some View { SignInWithAppleButton( // 1. onRequest: { request in request.requestedScopes = [.fullName, .email] }, onCompletion: { result in switch result { // 2. case .success (let authenticationResults): print("Authorization successful! :\(authenticationResults)") // 3. case .failure(let error): print("Authorization failed: " + error.localizedDescription) } } // 4. ).frame(width: 200, height: 50, alignment: .center) } }
이제 앱을 실행하면 Sign in with Apple 버튼이 표시됩니다.

버튼을 누르면 전체 이름과 이메일을 사용하여 인증하라는 메시지가 표시됩니다.

기존 코드 상단에 다음 코드를 추가하기만 하면 로그인 버튼을 Apple로 계속 버튼 또는 Apple로 등록 버튼으로 전환할 수 있습니다.
import SwiftUI import AuthenticationServices struct ContentView: View { var body: some View { SignInWithAppleButton( // Add this below for Sign up with Apple button .signUp, onRequest: { request in request.requestedScopes = [.fullName, .email] }, onCompletion: { result in switch result { case .success (let authenticationResults): print("Authorization successful! :\(authenticationResults)") case .failure(let error): print("Authorization failed: " + error.localizedDescription) } } ).frame(width: 200, height: 50, alignment: .center) } }

struct ContentView: View { var body: some View { SignInWithAppleButton( // Add this below for Continue with Apple button .continue, onRequest: { request in request.requestedScopes = [.fullName, .email] }, onCompletion: { result in switch result { case .success (let authenticationResults): print("Authorization successful! :\(authenticationResults)") case .failure(let error): print("Authorization failed: " + error.localizedDescription) } } ).frame(width: 200, height: 50, alignment: .center) } }

SwiftUI 프로젝트에 Sign in with Apple을 추가하는 것이 전부입니다. 이 블로그 코드는 내 Github에서 찾을 수 있습니다. UIKit에서 Apple로 로그인을 구현하는 방법을 보려면 제 다른 문서blog post를 확인하십시오.
읽어 주셔서 감사합니다. 이것이 다음 SwiftUI 프로젝트에 도움이 되기를 바랍니다!
꩜💻👨🏻💻 행복한 코딩하세요! 👨🏻💻💻꩜
Reference
이 문제에 관하여(SwiftUI 프로젝트에 Apple로 로그인을 추가하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/tprezioso/how-to-add-sign-in-with-apple-to-a-swiftui-project-nj4텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)