iOS

Mluvii provides two sets of framework for integration with your application. First framework uses webView from WebKit. 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
  • it is necessary to first 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
    }
...

Known issue: Due to the unavailability of getUserMedia in in-app WkWebView, video will not connect in Application

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.

For best user experience you should add following permissions to your info.plist: 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 whe user tries to upload file in mluvii chat

More info onApple Developer Portal

Sample Code:

//
//  ViewController.swift
//  TestWebkitWebview
//
//  Created by Mluvi Mac on 15.03.18.
//  Copyright © 2018 Mluvii. All rights reserved.
//

import UIKit
import WebKit
import MluviiChat

class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate{
    
    //MARK: Properties
    
    @IBOutlet weak var OpenButton: UIButton!
    var webView:WKWebView!
    var widgetState:Int32 = -1
    var chat: MluviiChatLibrary? = nil
    
    // Funkce, která zpracovává změnu stavu widgetu
    func statusUpdate(status: Int32) -> Void{
        print("Update status \(status)")
        widgetState = status
        if(widgetState == 0){
            OpenButton.backgroundColor = UIColor.gray
        }else if(widgetState == 1){
            OpenButton.backgroundColor = UIColor.green
        }else if(widgetState == 2){
            OpenButton.backgroundColor = UIColor.orange
        }
    }
    
    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
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        chat = MluviiChatLibrary()
        
        // Nastavení funkce, která určuje, co se má stát při zavření chatu
        chat?.setChatEnded {
            print("Minimize view")
            self.minimizeView()
        }
        
        // Nastavení funkce, která zpracovává změnu stavu
        chat?.setStatusUpdater(statusF: statusUpdate)
        
        // Vytvoření WKWebView, které načte url podle zadaného serveru, company GUID, tenant ID, preset name a požadovaného jazyku
        // url, companyGuid a tenantId jsou povinné proměnné, presetName, language a scope můžou být nil
        webView = chat?.createWebView(
            url: "apptest.mluvii.com",
            companyGuid: "295b1064-cf5b-4a5d-9e05-e7a74f86ae5e",
            tenantId: "1",
            presetName: "MluviiSDK",
            language: nil,
            scope: nil,
            navigationActionCustomDelegate: nil
        )
        self.view.addSubview(webView)
    }
    
    // Funkce, která otevře chat ve WebView a maximalizuje ho
    func maximizeWebView(){
        chat?.openChat()
    }
    
    // Funkce, která nastaví rozměry webView na 0,0 a změní url zpět na požadovaný widget
    func minimizeView(){
        chat?.resetUrl()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        print("Did receive memory warning")
    }
    
    
    //MARK: Actions

    @IBAction func TouchInside(_ sender: Any) {
        if(widgetState != -1){
            maximizeWebView()
        }
    }
    /**/
}

results matching ""

    No results matching ""