# iOS

Mluvii provides two sets of framework for integration with your application. The [first framework](https://github.com/mluvii/MluviiIOSLibrary) uses webView from WebKit. The [second framework](https://github.com/mluvii/mluviiIOSLibraryWithUIViewRepresentable) uses SwiftUI.

The code provided by us enables you to:

* initiate a webview with a widget with your company data
* notification on change of widget status
* open chat,
* close the chat and load a page with widget,
* handle navigation action on click to link in chat,

### Adding custom parameters

{% hint style="warning" %}
When adding customized parameters, you must first set them in the Administration Interface, see [Application](https://docs.mluvii.com/en/for-administrators/tenant-management/settings/application).
{% endhint %}

* Firstly, it's necessary to set parameters and then call `chat.openChat()`
* it is also necessary to call `chat.openChat()` and `chat.addCustomData()` after status update receive so its recommended to use callback chat.setStatusUpdater()

```
chat?.setStatusUpdater(statusF: statusUpdate)

private func statusUpdate(status: Int32) -> Void {
    ...
    chat.addCustomData(name: "param_name", value: "param_value")
    chat.openChat()
    ...
}
```

On link click inside chat custom handler:

* you can add custom `navigationActionCustomDelegate` when creating view

```
var chat = MluviiChatLibrary()
chat.createUIView(
    url: "apptest.mluvii.com",
    companyGuid: "295b1064-cf5b-4a5d-9e05-e7a74f86ae5e",
    tenantId: "1",
    presetName: nil,
    language: nil,
    scope: nil,
    navigationActionCustomDelegate: self.navigationActionDelegate
)
...
    public func navigationActionDelegate(webView: WKWebView, navigationAction: WKNavigationAction) -> WKWebView? {
        if navigationAction.targetFrame == nil, let url = navigationAction.request.url {
          if url.description.lowercased().range(of: "http://") != nil ||
            url.description.lowercased().range(of: "https://") != nil ||
            url.description.lowercased().range(of: "mailto:") != nil {
            UIApplication.shared.openURL(url)
          }
        }
      return nil
    }
...
```

{% hint style="danger" %}
***If you want to use a video, you need to enable your camera and microphone in your application.***
{% endhint %}

### Getting sessionStarted and sessionEnded events from app

Yoiú can capture sessionStarted and sessionEnded events with Callback function. Example of simple usage is shown below.

```
chat?.setMluviiEventCallbackFunc(eventF: { event, sessionId in
            print("Event and sessionID", event, sessionId ?? 0)
        })
```

{% hint style="success" %}
If a project downloaded from GitHub does not run because the “MluviiChat” framework cannot be found, we recommend that you recompile the “MluviiChat” project and replace the “MluviiChat.framework” file in the “TestWebkitWebview” project with the newly created “MluviiChat.framework” file.
{% endhint %}

{% hint style="danger" %}
Our framework is compiled for the minimum version of iOS 15.3.1.
{% endhint %}

If you want your app to work properly( file upload, camera and microphone), you need to add an explanation in the info.plist file why your app needs access to these permissions. Specifically, these items are:

* Privacy - Camera usage Description&#x20;
* Privacy - Microphone usage Description&#x20;
* Privacy - Media Library Usage Description

**If you will not add Media Library Usage Description app will crash when user tries to upload file in mluvii chat.**

More info on [Apple Developer Portal](https://developer.apple.com/documentation/uikit/protecting_the_user_s_privacy/accessing_protected_resources)

**Beware, in iOS 10 and above, if you don't have a definition in info.plist for what rights you need and the app tries to use it, the whole app crashes.**

## iOS Library

{% embed url="<https://github.com/mluvii/MluviiIOSLibrary>" %}

### Sample Code

It can be found [here](https://github.com/Mluvii/MluviiIOSLibrary/blob/master/TestWebkitWebview/TestWebkitWebview/ViewController.swift)
