swift - SwiftUI - 没有使用 HTTP 基本身份验证的自动填充凭据
问题描述
如果我想访问使用 http 基本身份验证的网页,我正在努力实现自动填充选项。
在我的应用程序的“正常”登录页面上访问自动填充工作正常(功能“自动填充凭据提供程序”设置正确)。
我首先尝试了 UIViewControllerRepresentable ,然后我使用了单独的 HostingController 但两者都有相同的行为:
UIViewController 可表示:
import SwiftUI
import SafariServices
struct SafariView: UIViewControllerRepresentable {
let url: URL
func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController {
return SFSafariViewController(url: url)
}
func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) {
}
}
单独的 HostingController:
import Foundation
import SwiftUI
import SafariServices
class HSHosting {
static var controller:UIViewController?
static var nextModalPresentationStyle:UIModalPresentationStyle?
static func openSafari(url:URL,tint:UIColor? = nil) {
guard let controller = controller else {
preconditionFailure("No controller present. Did you remember to use HSHostingController instead of UIHostingController in your SceneDelegate?")
}
let vc = SFSafariViewController(url: url)
vc.preferredBarTintColor = tint
controller.present(vc, animated: true)
}
}
class HSHostingController<Content> : UIHostingController<Content> where Content : View {
override init(rootView: Content) {
super.init(rootView: rootView)
HSHosting.controller = self
}
@objc required dynamic init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
if let nextStyle = HSHosting.nextModalPresentationStyle {
viewControllerToPresent.modalPresentationStyle = nextStyle
HSHosting.nextModalPresentationStyle = nil
}
super.present(viewControllerToPresent, animated: flag, completion: completion)
}
}
当我直接在 Safari 中打开相同的 URL 时,我按预期获得了 AutoFill 选项:
解决方案
推荐阅读
- elasticsearch - 如何构建一个后向边缘 n-gram 分词器
- django - 检查 url 状态而不打开它
- python - 从另一个运行 FTP 下载的线程更新 PyQt 进度
- c++ - 是否可以更改类成员缓冲区的大小
- jquery - 如何在 jquery 中添加类引用所以我悬停只在我的菜单中工作而不是到处
- c# - 将代码组织成新解决方案后的调试器跳过方法
- android - 找不到类 [org/drinkless/td/libcore/telegram/TdApi$Object]
- nuxeo - 如何卸载 Nuxeo Studio 安装的软件包?
- mysql - 我无法为迁移创建新表
- inotify - osquery inotify 是否在目录或文件上安装观察程序