gpt4 book ai didi

ios - 对于低于 iOS 13 的平台,您如何使用 WKWebView 处理 Apple Sign In?

转载 作者:行者123 更新时间:2023-12-05 07:00:43 24 4
gpt4 key购买 nike

我正在开发一款必须支持 Apple Sign In with iOS 10.0+ 的应用。对于最新的 iOS,我可以使用 AuthenticationServices native 库。这很好,但是,对于 iOS 10-12,我们希望使用 WKWebView 来处理应用程序中嵌入的身份验证,以在身份验证后获取 tokenemail(如果可能)完成了。

我正在关注苹果的官方指南: https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_js/incorporating_sign_in_with_apple_into_other_platforms

现在的问题是,当我配置 redirect_uri 时,如何在身份验证成功完成后从 WKWebView 取回 token ?我已经“尝试”拦截响应并通过 WKWebKit 的 WKNavigationDelegate navigationResponse 响应主体获取 token ,但无济于事。我遗漏了一个关键信息。

public func webView(_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
decisionHandler(.allow)
}
private func signInUsingWebAuthenticationSession() {

let queryItems = [
URLQueryItem(name: "client_id", value: "com.devapp.app"),
URLQueryItem(name: "redirect_uri", value: "https://dev.devapp.com/redirect"),
URLQueryItem(name: "response_type", value: "code id_token"), // Or code
URLQueryItem(name: "scope", value: "name email"), // Retrieve name and email
URLQueryItem(name: "response_mode", value: "form_post")
]

var urlComps = URLComponents(string: "https://appleid.apple.com/auth/authorize")!
urlComps.queryItems = queryItems

guard let authURL = urlComps.url else {
return
}

/// ... Load this url in WKWebView
}

我希望有一些聪明的开发人员以前遇到过/解决过这个问题,并且乐于分享他们的知识。干杯!

P.S 如果还有其他可行的解决方案,请随时发表评论

最佳答案

如果您支持低于 13 的 iOS 版本,您的应用将不会被批准。如果您需要使用 Apple ID 登录,您必须使用他们的 JS 解决方案,正如您已经猜到的旧版本。我也在努力寻找方法

关于ios - 对于低于 iOS 13 的平台,您如何使用 WKWebView 处理 Apple Sign In?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64060672/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com