Open your iOS project in XCode , select your target and drag SparkYouLib.xcframework folder to Frameworks, Libraries, and Embeded Content section
Step 2
In your ViewController.swift
Add import SparkYouLib to the top
Since we use delegate for communication between ViewController and the SparkYouWebView , your ViewController need to implement the SparkYouWebViewDelegate protocol. Modify your ViewController as below:
Implement two functions required by the SparkYouWebViewDelegate protocol
Now you can load SparkYou web app by creating new instance of SparkYouWebView class.
For example, below is a simple ViewController.swift file which contain a button to open the web view using SparkYouWebView class
@objc internal func sparkYouWebViewClosed() {
// Handle your view behavior when the WebView closed
}
@objc internal func sparkYouWebViewGetAccessToken() -> String {
// Please implement your way to get the access token of current
// logged in user in Associate Assistant application
return "ACCESS_TOKEN_HERE"
}
//
// ViewController.swift
//
import UIKit
import SparkYouLib
class ViewController: UIViewController, SparkYouWebViewDelegate {
var sparkYouWebView: SparkYouWebView!
var loadWebViewButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
loadWebViewButton = UIButton(type: .system)
loadWebViewButton.setTitle("Load Web View", for: .normal)
loadWebViewButton.addTarget(self, action: #selector(loadWebViewButtonTapped), for: .touchUpInside)
loadWebViewButton.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(loadWebViewButton)
NSLayoutConstraint.activate([
loadWebViewButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
loadWebViewButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
}
@objc private func loadWebViewButtonTapped() {
if(sparkYouWebView == nil){
sparkYouWebView = SparkYouWebView(url: "https://m-spark.dev.evehr.vn", delegate: self, showProgressBar: true)
view.addSubview(sparkYouWebView)
// Add auto layout constraints to make the SparkYouWebView fill the view
sparkYouWebView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
sparkYouWebView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
sparkYouWebView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
sparkYouWebView.topAnchor.constraint(equalTo: view.topAnchor),
sparkYouWebView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
}
sparkYouWebView.isHidden = false
// Hide the load button after it's tapped
loadWebViewButton.isHidden = true
}
@objc internal func sparkYouWebViewClosed() {
// Handle your view behavior when the WebView closed
// eg: show the button again and hide the webview
loadWebViewButton.isHidden = false
sparkYouWebView.isHidden = true
}
@objc internal func sparkYouWebViewGetAccessToken() -> String {
// Please implement your way to get the access token of current
// logged in user in Associate Assistant application
return "ACCESS_TOKEN"
}
}