美文网首页
SwiftUI 2.0 使用appleid 登录 —— Sign

SwiftUI 2.0 使用appleid 登录 —— Sign

作者: 刘铁崧 | 来源:发表于2021-02-18 23:52 被阅读0次
  • 注:
  1. 需要真机进行测试
  2. 需要开发者账号
  3. 需要导入 import AuthenticationServices 库
  4. 需要在Capability中进行配置

一步一步来,先上代码

import SwiftUI
import AuthenticationServices// 一定要导入
struct ContentView: View {
    @State private var message: String = "多行文本输入框"
    var body: some View {
        VStack{
            SignInWithAppleButton(.signIn) { request in
                request.requestedScopes = [.fullName,.email]//授权时显示的内容
            } onCompletion: { result in
                switch result{
                case .success(let success):
                    print(success)
                case .failure(let error):
                    print(error)
                }
            }
        }
    }
}

在Capability中进行配置
target -> Signing & Capabilities -> +Capability -> 搜索Sign In With Apple并添加


添加完底部会出现:

** 配置完就OK,记得在真机中测试即可~(不要用模拟器)*

相关文章

网友评论

      本文标题:SwiftUI 2.0 使用appleid 登录 —— Sign

      本文链接:https://www.haomeiwen.com/subject/fuggxltx.html