iOS SDK

Overview

Introduction

Here you can find instructions on how to integrate and use FriendlyScore Connect for iOS.

To get started quickly with FriendlyScore Connect for iOS, clone the GitHub repository and run the example. You will need to sign-up for the free API keys through our Developer Console.

Requirements

Quickstart Demo App

Clone and run the demo project from our GitHub repository.

Installation

FriendlyScore Connect is a framework distributed using CocoaPods dependency manager. If you are not familiar with this concept, please follow detailed instructions here.

To integrate, add FriendlyScoreConnect to your Podfile

pod 'FriendlyScoreConnect'

then run following command in your project main directory:

pod install

CocoaPods will install and embed all sources and dependencies into your app.

Implementation

When Connect is available in customer panel, the SDK will populate a grid of banks to enable connecting and data sharing.

App Delegate

Start with importing FriendlyScoreCore and FriendlyScoreConnect framework in your App Delegate:

import FriendlyScoreCore
import FriendlyScoreConnect

Then configure Connect in application:didFinishLaunchingWithOptions:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customisation after application launch.
    FriendlyScore.configureConnect()
    return true
}

In order to handle redirection properly, add line below to application(_:open:options:) function:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
        FriendlyScore.handleQueryParameters(for: url)

        return true
    }

Adding URL Types

Go to the Redirects section of the FriendlyScore developer console and provide your Bundle Identifier.

You will also need your Client Id for the specific environment (SANDBOX, DEVELOPMENT, PRODUCTION).

Navigate to your app target, create new URL Types object and add your bundle identifier to Identifier and URL Schemes field, as below:

UI

Start by importing FriendlyScoreCore:

import FriendlyScoreCore

Create the ClientId object

let myClientId = ClientId(stringLiteral: "YOUR_CLIENT_ID")

Create the Credentials object using userReference, which is any alphanumeric string that identifies the user in your systems. It can be used later to access information from the FriendlyScore API :

let myCredentials = Credentials(clientId: myClientId, userReference: "YOUR_USER_REFERENCE", environment: .sandbox)

Now, using the myCredentials object, you can present the FriendlyScore SDK anywhere in you code. Usually this can be done after the user's demand, e.g. tapping a button:

//somewhere in view controller
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 130, height: 45))
button.setTitle("Launch FriendyScore!", for: .normal)
button.addTarget(self, action: #selector(buttonTapHandler), for: .touchUpInside)

self.view.addSubview(button)

/**
...
..
*/

@objc func buttonTapHandler(button:UIButton) {
    FriendlyScore.show(with: myCredentials)
}

FriendlyScore will be presented as a modal view at the automatically found top-most view. Default modal presentation style is fullScreen. If you want to change it, please use the modalPresentationStyle property:

FriendlyScore.modalPresentationStyle = .pageSheet //or other

Events

FriendlyScore will populate different events at different stages. To handle events, please implement following:

FriendlyScore.eventsHandler = { event in
    switch event {
    case .userClosedView:
        print("SDK view closed by user.")
    case .userCompletedFlow:
        print("Friendy Score user completed flow.")
    }
}

Errors

To receive information about errors implement errorHandler that throws various FriendlyScoreError objects:

FriendlyScore.errorHandler = { error in
    switch error {
    case .userReferenceAuth:
        print("There was an authentication error for the supplied `userReference`")
    case .server: //unabled to get config
        print("There was a critical error on the server. SDK view closed automatically")
    case .serviceDenied: //wrong client id, access endpoint unpaid
        print("The service you are trying to connect is denied. Reason: \(error.description). SDK view closed automatically")
    }
}

Next Steps

Access to Production Environment

You can continue to integrate FriendlyScore Connect in your app in our sandbox and development environments. Once you have completed testing, you can request access to the production environment in the developer console or speak directly to your account manager.

Support

Find commonly asked questions and answers in our F.A.Q. You can also contact us via email at developers@friendlyscore.com or speak directly with us on LiveChat.

You can find all the code for FriendlyScore Connect for Web component, iOS and Android on our GitHub.