Saturday, October 14, 2023
HomeiOS Developmentios - How you can detect kind submission which is submitted by...

ios – How you can detect kind submission which is submitted by consumer


With this strategy, you’ll be able to detect the preliminary kind submission by the consumer and ignore any redirected URLs which have the identical navigation sort.

// Initialize formSubmittedByUser variable to false
var formSubmittedByUser = false

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    if navigationAction.navigationType == .formSubmitted && !formSubmittedByUser {
        // First kind submission by the consumer
        formSubmittedByUser = true
        // Deal with the shape submission
        // ...
        decisionHandler(.permit)
    } else {
        decisionHandler(.permit)
    }
}

func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
    if formSubmittedByUser {
        // Present navigation is a redirected URL from the preliminary kind submission
        formSubmittedByUser = false
    }
}

First, set a Boolean variable to trace whether or not the shape has been submitted by the consumer or not. For instance, you’ll be able to name this variable “formSubmittedByUser” and initialize it to false.

Then, within the webView:decidePolicyForNavigationAction:decisionHandler: technique, examine if the navigationType is WKNavigationTypeFormSubmitted and if the formSubmittedByUser variable is fake. If each circumstances are true, set the formSubmittedByUser variable to true and proceed with dealing with the shape submission.

Within the webView:didReceiveServerRedirectForProvisionalNavigation: technique, examine if the formSubmittedByUser variable is true. Whether it is true, then that the present navigation is a redirected URL from the preliminary kind submission. You may then reset the formSubmittedByUser variable to false in order that it may possibly detect the subsequent kind submission by the consumer.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments