I want to attach the Safari Debugger to the simulator in a turbo-ios native app. According to Joe Masilotti's blog post, you need to add the following code
let webView = WKWebView()
if #available(iOS 16.4, *) {
webView.isInspectable = true
}
let session = Session(webView: webView)
I cannot work out where to put this code. I have tried to do this in the class SceneDelegate
as follows
private let webViewConfiguration: WKWebViewConfiguration = {
let configuration = WKWebViewConfiguration()
configuration.applicationNameForUserAgent = " IOS-xyz/1.0"
// Enable inspection for Safari debugger
if #available(iOS 16.4, *) {
configuration.isInspectable = true
}
but this gives an error
Value of type 'WKWebViewConfiguration' has no member 'isInspectable'
So where do I put this code?
For context, here is the entire SceneDelegate Class, which is fairly standard for turbo-ios apart from the use of WKWebViewConfiguration.
import UIKit
import Turbo
import WebKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
private lazy var navigationController = UINavigationController()
private let webViewConfiguration: WKWebViewConfiguration = {
let configuration = WKWebViewConfiguration()
configuration.applicationNameForUserAgent = " IOS-xyz/1.0"
return configuration
}()
private func visit(url: URL) {
let viewController = VisitableViewController(url: url)
navigationController.pushViewController(viewController, animated: true)
session.visit(viewController)
}
// Initialize the Turbo Session with the custom configuration
private lazy var session: Session = {
let session = Session(webViewConfiguration: webViewConfiguration)
session.delegate = self
return session
}()
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
window!.rootViewController = navigationController
visit(url: URL(string: "http://myserver.com/sessions/new")!)
}
}
extension SceneDelegate: SessionDelegate {
func session(_ session: Session, didProposeVisit proposal: VisitProposal) {
visit(url: proposal.url)
}
func session(_ session: Session, didFailRequestForVisitable visitable: Visitable, error: Error) {
print("didFailRequestForVisitable: \(error)")
}
func sessionWebViewProcessDidTerminate(_ session: Session) {
session.reload()
}
}
isInspectable
is a property ofWKWebView
and it's not available withinWKWebViewConfiguration
.