# Secure Web Containers on iOS
source: https://developer.mastercard.com/open-finance-au/documentation/connect/integrating-with-connect/ios/websdk-ios/index.md

The following section explains the steps to load your WebApp via the Connect WebSDK in your iOS Mobile App inside a secure web container (`SFSafariViewController`), and seamlessly transition control to your Mobile app using the same `SFSafariViewController` (which either loads the FI OAuth login page or launches the FI's Mobile app if it is installed on the user's device).

This documentation also includes the Universal link Link/Deep Link configuration, as well as details on customizing the `WebViewClient` and secure web container (`SFSafariView Controller`) for enhanced control and handling of web interactions.

These are the steps which occur when launching:

* Launch your web app (integrated with the Connect WebSDK) URL address in a secure web container inside your mobile app.

* Select an option or link which will open the Connect experience in same Secure Container (note this option should have redirectUrl code integrated already).

* After successful FI OAuth account addition control returns to the your app. If the secure container case is launched, dismiss the secure container pop up using UISceneDelegate event of the universal link of the `redirectUrl`.

The following scenarios need to be handled:

* Scenario 1: FI's app is installed - the FI's app will launch and the OAuth session will occur in the FI's app.

* Scenario 2: FI's app is not installed - the FI OAuth login page will open in an SFSafariViewController.

## iOS project setup {#ios-project-setup}

Make sure you have set up the following in your XCode project:

* Under your Project target, select the **Signing and Capabilities** section:

  * Under this section click on **+Capability** to add a new capability, and select **Associated Domains** . Add your domain here. Under the **Signing** section, make sure you have set the development team correctly (or leave the team value as **None**).

  * This will create the entitlement file `YourProject.entitlements`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>com.apple.developer.associated-domains</key>
  <array>
    <string>applinks:*.example.com</string>
  </array>
</dict>
</plist>
```

## Loading your Web URL inside the Secure Web Container {#loading-your-web-url-inside-the-secure-web-container}

Add a close function and code to launch a Safari View Controller in the existing `ViewController` to help open the FI OAuth login screen (or to open the FI app for OAuth Login):

```swift
class ViewController : UIViewController, SFSafariViewControllerDelegate {

  var sfSafariViewController:SFSafariViewController? = nil

  override func viewDidAppear(_ animated: Bool) {
    launchSafari(url: "https://example.com")
  }

  func launchSafari(url:String){
    let sfSafariViewController:SFSafariViewController = SFSafariViewController(url: URL.init(string: url)!)
    sfSafariViewController.delegate = self
    self.present(sfSafariViewController, animated: true, completion: nil)
  }

  func closeChildWebViewOrPopUp(){
    if(self.presentedViewController != nil){
      self.dismiss(animated: true)
    }
  }

}
```

## Closing the secure web container {#closing-the-secure-web-container}

Add the following code in the SceneDelegate class to handle the closure of the secure web container:

```swift
// Scene delegate functions to close secure web container / webview pop up

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

 func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
   self.closeSecureContainerPopUp(url: userActivity.webpageURL)

 }

 func closeSecureContainerPopUp(url:URL?) {
   var viewController:ViewController = ViewController()

   if((self.window?.rootViewController?.children.count)! > 0) {
     viewController = self.window?.rootViewController?.children.last as! ViewController
     } else if (self.window?.rootViewController is ViewController) {
       viewController = self.window?.rootViewController as! ViewController
     }
     DispatchQueue.main.asyncAfter(deadline: .now() + 0.005) {
       viewController.closeChildWebViewOrPopUp()
     }         
   }
}
```

