-1

I'm opening an URL in UIWbView, where user can enter OTP and after submitting it'll provide following response:

{"success":true,""message":payment success"}

I want that if the value of success is true, I'll remove UIWebView from superview.

I don't know how to read the response from UIWebView.

Pratik Ghadia
  • 31
  • 1
  • 4

1 Answers1

0

I tried number of strings as parameter in stringByEvaluatingJavaScript(from:) but finally I figure it out by passing "document.body.innerHTML".

You can use "document.getElementById('someElement').innerText", if you want to read data from HTML elements/components like text fields, etc.

func webViewDidFinishLoad(_ webView: UIWebView) {
        print("WebView did finish load...")
        if !webView.isLoading {
            Loader.hideLoading()
        }
        let str = webView.stringByEvaluatingJavaScript(from: "document.body.innerHTML")
        if (str?.contains("\"success\":true"))! {
            print("Success is true")
            self.viewForWebView.removeFromSuperview()
        }else {
            print("Success is false or not found")
        }
    }
Pratik Ghadia
  • 31
  • 1
  • 4