IOS

Created by Daniel Arias · last update February 3, 2021

Requirements

  • Xcode 12.x
  • Swift 5.x
  • iOS 11.0
  • RxSwift as an external dependency

Installation

XAPPSClient contains RxSwift as external dependency.

These are currently the supported installation options.

Swift Package Manager

Inside your Xcode project, select File > Swift Packages > Add Package Dependency and enter repository URL:

https://github.com/empathyco/x-apps-customername-ios-releases.git

CocoaPods

Add the following pods XAPPSClient, XAPPSCore and RxSwift

1
2
3
4
5
6
7
8
9
10
11
12
# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
    pod 'XAPPSClient', :git => 'https://github.com/empathyco/x-apps-customername-ios-releases.git', :tag => '1.0.0'
    pod 'XAPPSCore', :git => 'https://github.com/empathyco/x-apps-ios-core-releases.git', :tag => '1.0.0'
    pod 'RxSwift', '6.0.0' 
end

target 'YOUR_TESTING_TARGET' do
    
end

Replace YOUR_TARGET_NAME and then, in the Podfile directory, type:

1
$ pod install

XCFramework

Each release includes *.xcframework framework binaries. Simply drag the needed framework binaries to your Frameworks, Libraries, and Embedded Content section under your target’s General tab.

Add the following XCFrameworks XAPPSClient, XAPPSCore and RxSwift*

To get these XCFrameworks files (XAPPSClient and XAPPSCore), download release as a zip ( https://github.com/empathyco/x-apps-customername-ios-releases/archive/main.zip ).

*RxSwift : Empathy uses RxSwift as an external dependency. Please check the installation RxSwift info, to add it to your project (Only when you are adding Empathy with CocoaPods or XCFramework).

Configuration

Init Empathy XAPPS Client in AppDelegate :

  • Default Configuration
1
2
3
4
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    EmpathyClient.init()
    return true
}
1
2
3
4
5
6
7
8
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let clientConfig = ClientConfiguration()
    clientConfig.catalogue = ConfigurationParameter("your-key-here", "your-value-here")
    clientConfig.store = ConfigurationParameter("your-key-here", "your-value-here")
    clientConfig.warehouse = ConfigurationParameter("your-key-here", "your-value-here")
    EmpathyClient.init(clientConfiguration: clientConfig)
    return true
}

Client Configuration

This is the list of parameters that are currently supported:

Parameter Type Required Default Description
instance string Yes 'eb-demo' Unique identifier of your Search API instance. It is provided by Empathy
environment string Yes '' Default value indicates production environment

Use staging for pre-production environment
lang ConfigurationParameter Yes 'es' Language to be used by X for internationalizing messages (i.e. language of the search interface).

If there are no translations for the specified language, the fallback language ('es') will be used.
catalogue ConfigurationParameter No nil Catalogue identifier used by X when querying the Search API.

Not applicable to all instances.
store ConfigurationParameter No nil Store identifier used by X when querying the Search API.

Not applicable to all instances.
warehouse ConfigurationParameter No nil Warehouse identifier used by X when querying the Search API.

Not applicable to all instances.
extra List<ConfigurationParameter> No nil Add extra ConfigurationParameter.

Not applicable to all instances.

Components

Use

To get a SearchBoxView you can add the view in the storyboard or in the code.

  • Code
1
2
3
4
5
6
7
8
9
10
11
12
public lazy var searchBoxCode: SearchBoxView = {
    return SearchBoxView(frame: .zero)
}()

override func viewDidLoad() {
    super.viewDidLoad()
    self.view.addSubview(searchBoxCode)
    searchBoxCode.topAnchor.constraint(equalTo: view.topAnchor, constant: 50).isActive = true
    searchBoxCode.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 10).isActive = true
    searchBoxCode.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -10).isActive = true
    searchBox?.heightAnchor.constraint(greaterThanOrEqualToConstant: 50).isActive = true
}
  • Storyboad
  1. Add new UIView component into your storyboard
  2. In Identity inspector, change the Class to SearchBoxView and Module to XAPPSClient

  3. Link SearchBoxView to ViewController


Listener

To get SearchBoxView actions callback. You need to implement the BaseSearchBoxDelegate in the ViewController

Method Parameter Type Description  
onSearchStateChanged enabled boolean Invoked when Search Box View opened or closed.  
onSearchConfirmed text String Invoked when search is confirmed, suggestion is selected or search button is clicked on the soft keyboard.

Parameter text contains the query.
 
onClearSearchButtonClicked - - Invoked when Search Box View clear button is clicked  
onCloseSearchButtonClicked - - Invoked when Search Box View close button is clicked  
onSearchButtonClicked - - Invoked when Search Box View search button is clicked  

Configuration

Work in progress ….