iOS

Mluvii provides two sets of framework for integration with your application. The first framework uses webView from WebKit. The second framework 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

When adding customized parameters, you must first set them in the Administration Interface, see Application.

  • 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
    }
...

If you want to use a video, you need to enable your camera and microphone in your application.

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)
        })

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.

Our framework is compiled for the minimum version of iOS 15.3.1.

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

  • Privacy - Microphone usage Description

  • 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

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

Sample Code

It can be found here

Last updated