> ## Documentation Index
> Fetch the complete documentation index at: https://razorpay-881012b3.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# UPI Intent in WebView - iOS

> Enable UPI Intent in WebView on your iOS app.

<div style={{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0.35rem 0.9rem",border:"1px solid rgba(128,128,128,0.28)",borderRadius:"0.5rem",padding:"0.45rem 0.75rem",margin:"0 0 1.25rem",fontSize:"0.875rem"}}>
  <span style={{fontWeight:600}}>Available in</span>
  <span>🇮🇳 India</span>
</div>

Follow the steps given below to enable UPI intent in WebView on your iOS application:

**1.1** [Setup App to Handle Deep Links](#1-1-setup-app-to-handle-deep-links)

**1.2** [Setup WKNavigationDelegate for WKWebView](#1-2-setup-wknavigationdelegate-for-wkwebview)

**1.3** [Conforming to WKNavigationDelegate](#1-3-conforming-to-wknavigationdelegate)

**1.4** [Enable UPI Intent Support](#1-4-enable-upi-intent-support)

## 1.1 Setup App to Handle Deep Links

Add the code given below to your `AppDelegate`. In this example, we override the `application(_:open:options:)` method to handle deep link URLs. You can use this method to parse the URL and determine which screen or content to display in your app.

<CodeGroup>
  ```swift Swift theme={null}
  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
      return true
  }
  ```

  ```objectivec Objective C theme={null}
  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
     return true
  }
  ```
</CodeGroup>

## 1.2 Setup WKNavigationDelegate for WKWebView

Get a reference to your `WKWebView` and call the `navigationDelegate` property to setup `WKWebView` using the following code. Add the `loadWebPage` function to load your content.

<CodeGroup>
  ```swift Swift theme={null}
  class CheckoutPaymentViewController: UIViewController {
      
      var checkoutUrl: String?

      // You can assign the checkout URL String to checkoutUrl property or pass it from previous page.
      
      @IBOutlet weak var wkWebView: WKWebView!
      
      override func viewDidLoad() {
          super.viewDidLoad()
          wkWebView.navigationDelegate = self
          self.loadWebPage()
      }
      
      func loadWebPage() {
          guard let urlString = self.checkoutUrl else { return }
          guard let url = URL(string: urlString) else { return }
          self.wkWebView.load(URLRequest(url: url))
      }
  }
  ```

  ```objectivec Objective C theme={null}
  #import <WebKit/WebKit.h>

  @interface WebViewController () <WKNavigationDelegate>
  {
      IBOutlet WKWebView *webView;
  }
  @end

  @implementation WebViewController

  - (void)viewDidLoad
  {
      [super viewDidLoad];
      webView.navigationDelegate = self;
      [self loadWebPage];
  }

  - (void)loadWebPage
  {
      NSURL *url = [[NSURL alloc] initWithString:@"<load-checkout-url-here>"];
      NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
      [webView loadRequest:urlRequest];
  }
  ```
</CodeGroup>

## 1.3 Conforming to WKNavigationDelegate

Create a `WKNavigationDelegate` to handle navigation events in your `WKWebView`.
In this example, we override the WebView`(_:decidePolicyFor:decisionHandler:)` method to handle navigation events in the WKWebView. If the URL scheme is not `http` or `https`, then we check if the URL can be opened using the `UIApplication.shared.canOpenURL()` method.

* If yes, then we open the URL using the `UIApplication.shared.open()` method.
* If not, then we allow the navigation to continue using the `decisionHandler(.allow)` method.

<CodeGroup>
  ```swift Swift theme={null}
  extension CheckoutPaymentViewController: WKNavigationDelegate {
      func webView(_ webView: WKWebView,
                   decidePolicyFor navigationAction: WKNavigationAction,
                   decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
          
          // If the request is a non-http(s) schema, then have the UIApplication handle opening the request.
          if let url = navigationAction.request.url,
             !url.absoluteString.hasPrefix("http://"),
             !url.absoluteString.hasPrefix("https://"),
             UIApplication.shared.canOpenURL(url) {
              
              // Have UIApplication handle the url (sms:, tel:, mailto:, ...)
              UIApplication.shared.open(url, options: [:], completionHandler: nil)
              
              // Cancel the request (handled by UIApplication).
              decisionHandler(.cancel)
          }
          else {
              // Allow the request.
              decisionHandler(.allow)
          }
      }
  }
  ```

  ```objectivec Objective C theme={null}
  - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
      NSURL *url = navigationAction.request.URL;
      NSString *urlString = url.absoluteString;
      BOOL hasHttpPrefix = [[urlString lowercaseString] hasPrefix:@"http://"];
      BOOL hasHttpsPrefix = [[urlString lowercaseString] hasPrefix:@"https://"];
      BOOL canOpenUrl = [[UIApplication sharedApplication] canOpenURL:url];
      
      if (!hasHttpPrefix && !hasHttpsPrefix && canOpenUrl) {
          NSDictionary *options = [[NSDictionary alloc] init];
          [[UIApplication sharedApplication] openURL:url options:options completionHandler:nil];
          
          decisionHandler(WKNavigationActionPolicyCancel);
      } else {
          decisionHandler(WKNavigationActionPolicyAllow);
      }
  }
  ```
</CodeGroup>

## 1.4 Enable UPI Intent Support

To enable and test UPI intent in WebView-based Checkout:

1. Open your website integrated with standard checkout.
2. Pass `webview_intent: true` parameter in the [payload](/docs/payments/payment-gateway/web-integration/standard/integration-steps#122-code-to-add-pay-button) sent to checkout to enable UPI intent support.
3. Ensure that UPI intent is triggered when the payment request is made.

<Warning>
  **Watch Out!**

  By default, the top PSP apps appear on the customer's mobile irrespective of the installation status of the UPI apps.
</Warning>

## List of Supported UPI Intent Apps

Given below is the list of supported UPI apps for Mobile Web.

* `gpay`
* `phonepe`
* `paytm`
