使用权限消息中缺少苹果名称的Apple登录

我正在尝试使用Sign in with Apple Auth0
但是权限消息显示我的应用名称为null

这是权限消息。

您是否要使用您的Apple ID“ myAppleId@email.com”登录null

我的应用程序徽标正确显示。应用名称显示null

我在哪里设置应用名称?

编辑:外观如下-

使用权限消息中缺少苹果名称的Apple登录

lisa7262 回答:使用权限消息中缺少苹果名称的Apple登录

在按请求范围发送请求时,您需要设置名称和电子邮件。

使用ASAuthorizationAppleIDProvider创建请求并初始化控制器ASAuthorizationController来执行请求的功能。

@objc func handleAppleIdRequest() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName,.email]
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = selfauthorizationController.performRequests()
}

成功登录后将调用以下功能。

func authorizationController(controller: ASAuthorizationController,didCompleteWithAuthorization authorization: ASAuthorization) {
if let appleIDCredential = authorization.credential as?  ASAuthorizationAppleIDCredential {
let userIdentifier = appleIDCredential.user 
let fullName = appleIDCredential.fullName 
let email = appleIDCredential.email
print(“User id is \(userIdentifier) \n Full Name is \(String(describing: fullName)) \n Email id is \(String(describing: email))”) }}
,

如果尝试使用Auth0,则可以采用以下方法解决此问题。
第1步。

if #available(iOS 13.0,*) {
    // Create the authorization request
    let request = ASAuthorizationAppleIDProvider().createRequest()

    // Set scopes
    request.requestedScopes = [.email,.fullName]

    // Setup a controller to display the authorization flow
    let controller = ASAuthorizationController(authorizationRequests: [request])

    // Set delegates to handle the flow response.
    controller.delegate = self
    controller.presentationContextProvider = self

    // Action
    controller.performRequests()
}

第2步
实现委托方法并在那里获取Apple的授权代码。

extension ViewController: ASAuthorizationControllerDelegate {
    @available(iOS 13.0,*)
    func authorizationController(controller: ASAuthorizationController,didCompleteWithAuthorization authorization: ASAuthorization) {
        if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
            // Success
            guard let authorizationCode = appleIDCredential.authorizationCode,let authCode = String(data: authorizationCode,encoding: .utf8) else {
                    print("Problem with the authorizationCode")
                    return
            }
         }
    }
}

第3步
现在,您可以使用此authCode登录到Auth0。

func appleSignin(with authCode: String)  {
    Auth0.authentication().tokenExchange(withAppleAuthorizationCode: authCode)
        .start { result in
            switch result {
            case .success(let credentials):
            //LoginSucces
            case .failure(let error):
                //Issue with login.
            }
    }
}

在这种方法中,您不会像使用Auth0的其他登录方法那样显示Web视图。
我已将其发布在Auth0社区(我在此处发布的问题)上,他们的一位工程师回答我以这种方式进行处理。 查阅更多信息Sign in with Apple - Auth0

本文链接:https://www.f2er.com/2678988.html

大家都在问