首页 > 解决方案 > SwiftUI (5.3) “苹果登录”

问题描述

我正在尝试使用 Apple 登录/向上按钮实现 SwiftUI (5.3)“Apple 登录”。分享我的代码,请帮我弄清楚这段代码有什么问题。NavigationLink 目标在单击苹果登录按钮后立即到达,而不显示/询问凭据。

import SwiftUI
import CoreData
import AuthenticationServices


struct ContentView: View {
    @State private var isUserAuthed = false
    @State private var user: UserAuth = UserAuth()


    var body: some View {
        NavigationView{
            NavigationLink(destination: HomeView(), isActive: $isUserAuthed){
                SignInWithAppleButton(
                    .signIn,
                        onRequest: { request in
                            request.requestedScopes = [.fullName, .email]
                        },
                        onCompletion: { result in
                            switch result {
                            case .success (let authResults):
                                print("---Authorization successful.")
                                isUserAuthed = true
                            case .failure (let error): 
                                print("Authorization failed: " + error.localizedDescription)
                            }
                        }
                ).frame(width: 300, height: 50, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)                                                           
            }

标签: swiftuiapple-sign-in

解决方案


推荐阅读