# Using the Connect iOS SDK
source: https://developer.mastercard.com/open-finance-au/documentation/connect/integrating-with-connect/ios/ios-sdk/index.md

The Connect iOS SDK is distributed as a compiled binary in XCFramework format which allows you to easily integrate our SDK into your development projects. Our Connect iOS SDK has full Bitcode support so that you don't have to disable it in your applications when integrating with the SDK.

The XCFramework format is Apple's officially supported format for distributing binary libraries to multiple platforms and architectures in a single bundle.
Note: Chase bank (JPMorgan Chase) has removed support for certain types of WebView traffic. This will impact the Chase OAuth flow if your SDK integration is not using the most recent version of our Connect iOS SDK. The latest version will support secure web containers, for example, `SFSafariviewcontroller`. For more information, see the [Chase Developer documentation](https://developer.chase.com/products/aggregation-consent/guides/launching-the-oauth-flow-in-a-secure-container/) Warning: The Connect iOS SDK does not support the Connect Transfer flow (for Deposit Switch and Bill Pay Switch). We provide a separate Connect Transfer iOS SDK for this purpose.

## Compatibility {#compatibility}

* Supports iOS 15.6 or later.

Warning: Support for deepLinkUrl parameters is deprecated from version 3.0.0 of the Connect iOS SDK. Going forward you should use the `redirectUrl` parameter, which supports both universal and deep links. For more information [see our Github documentation](https://github.com/Mastercard/connect-ios-sdk/blob/main/README.md)

## Install the Connect iOS SDK {#install-the-connect-ios-sdk}

Install the Connect iOS SDK using the Swift Package Manager, CocoaPods, or by manually dragging` Connect.xcframework` into your Xcode project.
Tip: If you are currently using the legacy iOS framework, you must [migrate to XCFramework](https://developer.mastercard.com/open-finance-au/documentation/connect/integrating-with-connect/ios/ios-sdk/index.md#migrate-from-framework-to-xcframework) before installing the Connect iOS SDK.

### Swift Package Manager {#swift-package-manager}

To install the Connect iOS SDK do the following steps in your project in Xcode.

If you've previously used CocoaPods, remove them from the project with the `pod deintegrate` command.

1. Add a package by selecting **File → Add Packages...** in Xcode's menu bar.
2. Search for the Connect iOS SDK using the repo's URL: `https://github.com/Mastercard/connect-ios-sdk`
3. Next, set the **Dependency Rule** to be **Up to Next Major Version** to get the latest Connect SDK.
4. Then, click **Add Package**.

### CocoaPods {#cocoapods}

To install the Connect iOS SDK include the following in your Podfile.

```html
use_frameworks!
pod 'MastercardOpenBankingConnect'
```

### Manual Install {#manual-install}

1. Download the Connect iOS SDK from [Github](https://github.com/Mastercard/connect-ios-sdk).
2. Open your project in Xcode and drag the Connect.xcframework folder into your project.
3. In the build settings for the target folder, select the General tab.
4. Scroll down to the Frameworks, Libraries, and Embedded Content section, and select Connect.xcframework.
5. Under the Embed column, select Embed \& Sign from the menu drop-down list if it is not already selected.

## Integrating Using UIKit {#integrating-using-uikit}

1. Add `import Connect` to all your source files that make calls to the Connect iOS SDK:

```swift
import UIKit
import Connect
```

2. Generate a valid URL (see [Generate Connect URL APIs](https://developer.mastercard.com/open-finance-au/documentation/connect/generate-2-connect-url-apis/index.md)).
3. Create an instance of the `ConnectViewController` class and assign `ConnectEventDelegate` to `ConnectViewController`. Use the Connect URL in the load function (see `connectUrl` in the following code example).
4. Create callback/delegate functions for `onLoad`, `onDone`, `onCancel`, `onError`, `onRoute`, and `onUser` events. These callback functions will have a `NSDictionary?` parameter that contains data about the event. For more information see the list of [Connect callback events](https://developer.mastercard.com/open-finance-au/documentation/connect/integrating-with-connect/index.md#callback-events).
5. In the `onLoad` callback delegate method, present the `ConnectViewController` using a `UINavigationController` with the `ConnectViewcontroller` as its `rootViewController`.

**Note** : The `ConnectViewController` automatically dismisses when the Connect flow is completed, cancelled early by the user, or when an error occurs.

### Example {#example}

The following is an example of the delegate functions and their usage.

```swift
ViewController: UIViewController, ConnectEventDelegate {

  @IBOutlet var activityIndicator: UIActivityIndicatorView!

 // Declaration of View and Navigation controllers
  var connectViewController: ConnectViewController!
  var connectNavController: UINavigationController!
  var connectUrl: String?

  // For regular Connect flow use below openConnect function
  func openConnect(connectUrl: String) {
      self.connectViewController = ConnectViewController()
      self.connectViewController.delegate = self
      self.connectViewController.load(connectUrl!)
  }

  // MastercardOpenBankingConnect Delegate Methods
  func onCancel(_ data: NSDictionary?) {
      print("onCancel:")
      displayData(data)
      self.activityIndicator.stopAnimating()
      // Needed to trigger deallocation of ConnectViewController
      self.connectViewController = nil
      self.connectNavController = nil
  }

  func onDone(_ data: NSDictionary?) {
      print("onDone:")
      displayData(data)
      self.activityIndicator.stopAnimating()
      // Needed to trigger deallocation of ConnectViewController
      self.connectViewController = nil
      self.connectNavController = nil
  }

  func onError(_ data: NSDictionary?) {
      print("onError:")
      displayData(data)
      self.activityIndicator.stopAnimating()
      // Needed to trigger deallocation of ConnectViewController
      self.connectViewController = nil
      self.connectNavController = nil
  }

  func onLoad() {
      print("onLoad:")
      self.connectNavController = UINavigationController(rootViewController: self.connectViewController)
      if #available(iOS 13.0, *) {
          self.connectNavController.modalPresentationStyle = .automatic
          self.connectNavController.isModalInPresentation = true
      } else {
          // Fallback on earlier versions
      }

      self.connectNavController.presentationController?.delegate = self
      self.present(self.connectNavController, animated: true)
  }

  func onRoute(_ data: NSDictionary?) {
      print("onRoute:")
      displayData(data)
  }

  func onUser(_ data: NSDictionary?) {
      print("onUser:")
      displayData(data)
  }

  func displayData(_ data: NSDictionary?) {
      print(data?.debugDescription ?? "no data in callback")
  }
```

## Integrating Using SwiftUI {#integrating-using-swiftui}

1. Add `import Connect` to all your source files that make calls to the Connect iOS SDK:

```swift
import SwiftUI
import Connect
```

2. Generate a valid URL (see [Generate Connect URL APIs](https://developer.mastercard.com/open-finance-au/documentation/connect/generate-2-connect-url-apis/index.md)).
3. Create an instance of the `ConnectView` with the Connect URL and assign `ConnectViewEventDelegate` as `self` to get the events (see `connectUrl` in the following code example).
4. Create callback/delegate functions for `onLoad`, `onDone`, `onCancel`, `onError`, `onRoute`, and `onUser` events. These callback functions will have a `NSDictionary?` parameter that contains data about the event. For more information see the list of [Connect callback events](https://developer.mastercard.com/open-finance-au/documentation/connect/integrating-with-connect/index.md#callback-events).

### Example {#example-1}

The following is an example of the delegate functions and their usage.

```swift
struct ContentView: View {

    @State var connectUrl: String = ""
    @State var presentConnect: Bool = false

    var body: some View {
        VStack {
            //....

            Your View

            ....//
        }
        .fullScreenCover(isPresented: $presentConnect) {
            // For regular Connect flow use below initialiser
            ConnectView(connectUrl: connectUrl,
                        delegate: self)
        }
    }

    func displayData(_ data: NSDictionary?) {
        print(data?.debugDescription ?? "no data in callback")
    }
}

// MastercardOpenBankingConnect Delegate Methods
extension ContentView: ConnectViewEventDelegate{
    func onCancel(_ data: NSDictionary?) {
        print("onCancel:")
        displayData(data)

        // Needed to dismiss the ConnectView
        presentConnect = false
    }

    func onDone(_ data: NSDictionary?) {
        print("onDone:")
        displayData(data)

        // Needed to dismiss the ConnectView
        presentConnect = false
    }

    func onError(_ data: NSDictionary?) {
        print("onError:")
        displayData(data)

        // Needed to dismiss the ConnectView
        presentConnect = false
    }

    func onLoad() {
        print("onLoad:")
    }

    func onRoute(_ data: NSDictionary?) {
        print("onRoute:")
        displayData(data)
    }

    func onUser(_ data: NSDictionary?) {
        print("onUser:")
        displayData(data)
    }
}
```

## Sample App {#sample-app}

[Github](https://github.com/Mastercard/connect-ios-sdk) contains a sample Swift application called ConnectWrapper (requires Xcode 11 or greater) that demonstrates integration and use of the Connect iOS SDK.

## Migrate From Framework to XCFramework {#migrate-from-framework-to-xcframework}

The Connect iOS SDK uses the XCFramework format which allows you to easily integrate the SDK into your development projects. Our iOS SDK has full bitcode support so that you don't have to disable bitcode in your applications.

### Delete Connect.framework from your project {#delete-connectframework-from-your-project}

If you're currently using framework in your projects, then you need to remove it before you start using the XCFramework. This ensures that the `connect.framework` won't interfere with the new XCFramework while you're trying to compile your source code.
Warning: Before deleting your existing framework, test the new XCFramework, and make sure it is working correctly so that you don't accidentally delete your source files.

1. Open your project in Xcode.
2. Click the General tab.
3. Scroll down to the **Frameworks** , **Libraries** , and **Embedded Content** section.
4. Select connect.framework.
5. To delete the framework, click (--) minus.

### Remove the Connect.framework reference {#remove-the-connectframework-reference}

1. From **Project Navigator** on the left pane, select **Framework** and press **Delete**.
2. Click **Remove Reference** (recommended) Note: This is the safest option to preserve your source files.

### Remove run script {#remove-run-script}

If you've incorporated our script for stripping out the X86 simulator before submitting your application to the Apple App Store, you can remove the run script. It's no longer needed with the XCFramework. Only customers that create a run script to incorporate with the connect-sdk-iOS-v1.2.0.zip need to do this step.

1. From Xcode in the right pane, select your **Targets**.
2. On the **Build Phase** tab, scroll down to **Run Script**
3. To remove the script, click the x.

Once you have migrated from the legacy framework to the new XCFramework, you can install the Connect iOS SDK via [CocoaPods](https://developer.mastercard.com/open-finance-au/documentation/connect/integrating-with-connect/ios/ios-sdk/index.md#cocoapods)
