小编uch*_*cha的帖子

如何使用 ASWebAuthenticationSession 获取授权码?

我正在尝试使用 ASWebAuthenticationSession 从Stripe 的 OAuth 端点获取身份验证代码 - 此事件在调用我的 Stripe 重定向 url 后发生。

不幸的是,authSession 的完成处理程序不会使用callbackURL 进行回调。我需要这个callbackURL来查询授权码。我读过有关该主题的不同文章,但我不明白为什么我的实现没有按照我期望的方式工作。

这是我的代码:


class CreateStripeConnectAccountController: UIViewController {

  var authSession: ASWebAuthenticationSession!

  override func viewDidLoad() {
      super.viewDidLoad()
      configureAuthSession()
  }

  private func configureAuthSession() {

    let urlString = Constants.URLs.stripeConnectOAuth // Sample URL

    guard let url = URL(string: urlString) else { return }

    let callbackScheme = "myapp:auth"    

    authSession = ASWebAuthenticationSession(url: url, callbackURLScheme: callbackScheme, completionHandler: { (callbackURL, error) in
       guard error == nil, let successURL = callbackURL else {
          print("Nothing")
          return
       } …
Run Code Online (Sandbox Code Playgroud)

oauth ios stripe-payments swift aswebauthenticationsession

8
推荐指数
1
解决办法
9743
查看次数

如何将 UISearchController 与 SwiftUI 集成

我有一个符合 UIViewControllerRepresentable 的 SearchController,并且我已经实现了所需的协议方法。但是,当我在 SwiftUI 结构中创建 SearchController 的实例时,SearchController 在加载后不会出现在屏幕上。有没有人对如何将 UISearchController 与 SwiftUI 集成有任何建议?谢谢!

这是符合 UIViewControllerRepresentable 的 SearchController Struct:

struct SearchController: UIViewControllerRepresentable {

    let placeholder: String
    @Binding var text: String

    func makeCoordinator() -> Coordinator {
        return Coordinator(self)
    }

    func makeUIViewController(context: Context) -> UISearchController {
        let controller = UISearchController(searchResultsController: nil)
        controller.searchResultsUpdater = context.coordinator
        controller.obscuresBackgroundDuringPresentation = false
        controller.hidesNavigationBarDuringPresentation = false
        controller.searchBar.delegate = context.coordinator
        controller.searchBar.placeholder = placeholder

        return controller
    }

    func updateUIViewController(_ uiViewController: UISearchController, context: Context) {
        uiViewController.searchBar.text = text
    }

    class Coordinator: NSObject, …
Run Code Online (Sandbox Code Playgroud)

xcode swift uisearchcontroller swiftui

7
推荐指数
2
解决办法
2812
查看次数