import UIKit extension RDEPUBReaderController { func openExternalURLIfAllowed(_ url: URL) { guard shouldAllowExternalURL(url) else { return } if configuration.requiresExternalLinkConfirmation { presentExternalLinkConfirmation(for: url) } else { UIApplication.shared.open(url, options: [:], completionHandler: nil) } } private func shouldAllowExternalURL(_ url: URL) -> Bool { guard let scheme = url.scheme?.lowercased() else { return false } if delegate?.epubReader(self, shouldOpenExternalURL: url) == false { return false } return configuration.allowedExternalURLSchemes.contains(scheme) } private func presentExternalLinkConfirmation(for url: URL) { let alert = UIAlertController( title: "打开外部链接", message: url.absoluteString, preferredStyle: .alert ) alert.addAction(UIAlertAction(title: "取消", style: .cancel)) alert.addAction(UIAlertAction(title: "打开", style: .default) { _ in UIApplication.shared.open(url, options: [:], completionHandler: nil) }) present(alert, animated: true) } }