使用未声明的类型 WKActionSheet

Use of undeclared type WKActionSheet

我将 WebKitWKWebView 一起使用,我试图截取长按 link 后出现的 WKActionSheet

在我的根视图控制器中,我实现了 present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil):

override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {

    print("View controller to present: \(viewControllerToPresent)")

    super.present(viewControllerToPresent, animated: flag, completion: completion)
}

当我长按 link 时,我可以在我的控制台中看到相关日志:

View controller to present: <WKActionSheet: 0x13616b200>

但是如果我尝试检查 viewControllerToPresent 是否是 WKActionSheet,那么我会收到此错误消息:

Use of undeclared type WKActionSheet

所以我猜...这个WKActionSheet属于私人API?无法访问 class ?

我如何确定 viewControllerToPresent 是否是一个干净的 WKActionSheet?现在,我正在使用 viewControllerToPresent.description 并检查它是否包含字符串 "WKActionSheet";还可以,但是很脏...

如果有人感兴趣,这是我现在的解决方法。

override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil)
{
    guard let alertController = viewControllerToPresent as? UIAlertController,
        alertController.preferredStyle == .actionSheet, alertController.description.contains("WKActionSheet")
        else {
            super.present(viewControllerToPresent, animated: flag, completion: completion)
            return
    }

    guard let longPressedLink = alertController.title
        else {return}

    // Here I call a custom method to create my own UIAlertController
    let customAlertController = getCustomAlertControllerFromLink(link: longPressedLink)
    super.present(customAlertController, animated: flag, completion: completion)
}