Setup

Nabla iOS SDK Installation & Quick Start

Integrating the SDK

SPM

The Nabla Messaging UI SDK is compatible with iOS 13 and higher.

The recommended way to install our SDK is via Swift Package Manager.

Open your .xcodeproj, select the option "Add Package..." in the File menu, and paste this URL:

https://github.com/nabla/nabla-ios

Xcode will look for the Products available in the Package. Select NablaMessagingCore and NablaMessagingUI. Press "
Add Package" and Xcode will download the dependencies.

Add package on XcodeAdd package on Xcode

Go to your app's target and make sure that NablaMessagingCore and NablaMessagingUI have been added
to Frameworks, Libraries and Embedded Content.

Added packages on XcodeAdded packages on Xcode

Cocoapods

Add the following dependencies in your Podfile

pod 'NablaMessagingUI'
pod 'NablaMessagingCore'

And then run pod install to update your project.

Setup

You are now ready to setup the Nabla SDK. The first thing is to initialize the NablaClient.

class AppDelegate: UIResponder, UIApplicationDelegate {
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
      NablaClient.initialize(apiKey: "YOUR_API_KEY")
      
      // ...
    }
}

The NablaClient can then be accessed from anywhere with NablaClient.shared.

Authenticate the app user

Once a user is authenticated in the app, you can authenticate them to the Nabla's SDK so that they can securely access their conversations.

The authenticate(userId:provider:) method requires a SessionTokenProvider that you must implement. It will be called every time the Nabla SDK needs to authenticate the user, and you are responsible for providing an accessToken and a refreshToken from your backend. See server side documentation for more details.

The userId is used to identify the user and will be passed to your SessionTokenProvider when provideTokens(userId:completion:) is called.

class AppDelegate: UIResponder, UIApplicationDelegate {
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
      NablaClient.initialize(apiKey: "YOUR_API_KEY")
      
      NablaClient.shared.authenticate(userId: myUserId, provider: self)
      
      // ...
    }
}

extension AppDelegate: SessionTokenProvider {
    func provideTokens(userId: UUID, completion: (Tokens?) -> Void) {
        // Use your own backend to get the tokens for your user
        myService.getAuthTokens() { tokens in
            completion(tokens)
        }
    }
}

The example above makes AppDelegate implement SessionTokenProvider. For production application, we recommend that SessionTokenProvider is implemented by another class, usually responsible for the authentication in the other parts of your app.

Make sure you call authenticate before calling any other method of the SDK, otherwise a NablaError.authenticationError will be returned as Result.

Your first start

You're now ready to launch the app and you should see a log after authenticating the user

User authentication successful

You're now ready to start integrating the messaging components.


Did this page help you?