0

working on my swift app here.

Below is the code I have,

struct WebView: UIViewRepresentable {
    @State var allowsInLineMediaPlayback = true
    let request: URLRequest//pass the website to webkit


    func makeUIView(context: Context) -> WKWebView {
        let configuration = WKWebViewConfiguration()
        configuration.allowsInlineMediaPlayback = true
        configuration.mediaTypesRequiringUserActionForPlayback = []
        let webView = WKWebView(frame: .zero, configuration: configuration)
        return webView

    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
        uiView.load(request)

    }
}

class ViewController: UIViewController {

var webView = WKWebView()
    override func viewDidLoad() {
        super.viewDidLoad()

        NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActive),
                                               name: UIApplication.didBecomeActiveNotification, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(willResignActive),
                                               name: UIApplication.willResignActiveNotification, object: nil)
    }
    @objc func willResignActive(){
        disableIgnoreSilentSwitch(webView)

    }

    @objc func didBecomeActive() {
        //Always creates new js Audio object to ensure the audio session behaves correctly
        forceIgnoreSilentHardwareSwitch(webView, initialSetup: false)
    }

and I am getting an error with this part with webView,

disableIgnoreSilentSwitch(webView)

The error states Cannot convert value of type '(WKWebView, WKNavigation?) -> ()' to expected argument type 'WKWebView' Thanks in advance. If it helps, I am using the code from here as reference. How to force WKWebView to ignore hardware silent switch on iOS?

enter image description here

Thomas Kim
  • 33
  • 1
  • 5
  • For me the code on the referenced website works. How do you connect your ViewController to your SwiftUI code? I don't understand your example. – krjw Jan 23 '20 at 12:27
  • I was using swiftUI, so I didnt use class so I couldn't do the override and object functions, so I added extra class. May I see your code? Thanks! – Thomas Kim Jan 26 '20 at 07:53
  • Plus, I am using swiftui not storyboard. – Thomas Kim Jan 30 '20 at 05:17

0 Answers0