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

The Data 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 Data 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 Data 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 Data 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. See the [Deposit Switch and Bill Pay Switch documentation](https://developer.mastercard.com/open-finance-us/documentation/products/pay/switch/index.md) for details.

## Compatibility {#compatibility}

* Supports iOS 15.6 or later.

Warning: Support for deepLinkUrl parameters is deprecated from version 3.0.0 of the Data 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 Data Connect iOS SDK {#install-the-data-connect-ios-sdk}

Install the Data 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-us/documentation/connect/integrating/sdk/ios/ios-sdk/index.md#migrate-from-framework-to-xcframework) before installing the Data Connect iOS SDK.

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

To install the Data 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 Data 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 Data Connect SDK.
4. Then, click **Add Package**.

### CocoaPods {#cocoapods}

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

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

### Manual Install {#manual-install}

1. Download the Data 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 Data Connect iOS SDK:

```swift
import UIKit
import Connect
```

2. Generate a valid URL (see [Generate Data Connect URL APIs](https://developer.mastercard.com/open-finance-us/documentation/connect/generate-2-connect-url-apis/index.md)).
3. Create an instance of the `ConnectViewController` class and assign `ConnectEventDelegate` to `ConnectViewController`. Use the Data 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 [Data Connect callback events](https://developer.mastercard.com/open-finance-us/documentation/connect/integrating/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 Data 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 Data Connect flow use below openConnect function
  func openConnect(connectUrl: String) {
      self.connectViewController = ConnectViewController()
      self.connectViewController.delegate = self
      self.connectViewController.load(connectUrl!)
  }

  // For App to App Data Connect flow use below openConnect function
  func openConnect(connectUrl: String) {
      self.connectViewController = ConnectViewController()
      self.connectViewController.delegate = self
      self.connectViewController.load(connectUrl,redirectUrl: "https://example.com/connect")
  }


  // 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 Data Connect iOS SDK:

```swift
import SwiftUI
import Connect
```

2. Generate a valid URL (see [Generate Data Connect URL APIs](https://developer.mastercard.com/open-finance-us/documentation/connect/generate-2-connect-url-apis/index.md)).
3. Create an instance of the `ConnectView` with the Data 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 [Data Connect callback events](https://developer.mastercard.com/open-finance-us/documentation/connect/integrating/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 Data Connect flow use below initialiser
            ConnectView(connectUrl: connectUrl,
                        delegate: self)

                    // OR

            // For App to App Data Connect flow use below initialiser
            ConnectView(connectUrl: connectUrl,
                        redirectUrl: "https://example.com/connect",
                        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)
    }
}
```

## App to App support {#app-to-app-support}

To provide the best app to app authentication experience for your customers, you should send a universal link URL in the `redirectURL` parameter when using Data Connect. See [App To App Authentication](https://developer.mastercard.com/open-finance-us/documentation/connect/integrating/index.md#app-to-app-authentication) for more details,
including [how to test](https://developer.mastercard.com/open-finance-us/documentation/connect/integrating/index.md#how-to-test-app-to-app-authentication).

Before installing the Data Connect iOS SDK for use with app to app authentication, complete the following:

* Create your domain's `redirectUrl` (universal link)
* Configuring your `redirectUrl`

### Create your domain's redirectUrl {#create-your-domains-redirecturl}

For information on how to create a universal Link to be used as redirectUrl in your application, see [Apple's Allowing apps and websites to link to your content](https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content) for details.
Tip: In order to provide the best app to app authentication customer experience, you should use a universal link for `redirectUrl`.

We do not recommend using a deep link (custom URL scheme) for `redirectUrl` since deep links lack the security of universal Links through the two-way association between your app and your website. A deep link will also trigger an alert on iOS devices that can add friction to the customer experience, requesting permission to redirect back to the Partner's app.

Any application can register custom URL schemes and there is no further validation from iOS. If multiple applications have registered the same custom URL scheme, a different application may be launched each time the URL is opened. To complete OAuth flows, it is important that your application is opened and not any arbitrary application that has registered the same URL scheme.

### Configuring your redirectUrl {#configuring-your-redirecturl}

The `redirectUrl` URL is used to redirect back to your mobile app after completing the FI's OAuth flow (this should be a universal link).

Here is an example of a universal link redirectUrl within your code: `self.connectViewController.load(connectUrl,redirectUrl: "https://example.com/mastercardConnect")`

For information on how to configure your server see [supporting associated domains](https://developer.apple.com/documentation/xcode/supporting-associated-domains)

## 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 Data Connect iOS SDK.

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

The Data 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 Data Connect iOS SDK via [CocoaPods](https://developer.mastercard.com/open-finance-us/documentation/connect/integrating/sdk/ios/ios-sdk/index.md#cocoapods)
