View controller setup example
View controller setup example
//
// ViewController.swift
// WishiSDKTestApp
//
import UIKit
import WishiSDK
class ViewController: UIViewController, WishiSDKDelegate {
private let partnerId = "***"
private var userId: String = ""
private var partnerId: String = ""
private let savedUserLabel: UILabel = UILabel.init(frame: CGRect.zero)
private static let savedClientId = "savedClientId"
private static let savedPartnerId = "savedPartnerId"
private static let savedClientEmail = "savedClientEmail"
private static let savedClientPassword = "savedClientPassword"
private static let savedUserEmail = ""
private static let savedUserPassword = ""
@IBOutlet weak var initSDKButton: UIButton!
@IBOutlet weak var launchButton: UIButton!
@IBOutlet weak var clientIdLabel: UILabel!
@IBOutlet weak var versionLabel: UILabel!
@IBOutlet weak var container: UIView!
@IBOutlet weak var usernameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var firstNameTextField: UITextField!
@IBOutlet weak var lastNameTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
container.layer.borderColor = UIColor.systemPink.cgColor
initSDKButton.layer.borderColor = UIColor.systemPink.cgColor
launchButton.layer.borderColor = UIColor.systemPink.cgColor
}
@IBAction func launchPressed() {
if let navigation = self.navigationController {
Wishi.shared.launch(from: navigation)
}
}
@IBAction func logoutPressed() {
Wishi.shared.logout()
}
@IBAction func initSDKButtonPressed() -> Void {
guard let firstName = firstNameTextField.text,
let lastName = lastNameTextField.text else {
return
}
let configuration = Configurations.init(configuration: getConfiguration())
let sdkPartnerId = partnerId.isEmpty ? self.partnerId : partnerId
var email = ""
var password = ""
if let text = usernameTextField.text, !text.isEmpty {
email = text
}
if let text = passwordTextField.text, !text.isEmpty {
password = text
}
let partnerToken = "PARTNER_ACCESS_TOKEN"
let partnerUserId = "PARTNER_USER_ID"
let sdkPartnerId = "PARTNER_ID"
DispatchQueue.main.async {
let clientInfo = ClientInfo.init(firstName: firstName,
lastName: lastName,
email: email)
do {
let jwt = try decode(jwt: partnerToken)
let body = jwt.body
guard let partnerUserId = body["uuid"] as? String else {
return
}
Wishi.shared.initSDK(clientInfo: clientInfo,
partnerKey: sdkPartnerId,
partnerToken: partnerToken,
partnerUserId: partnerUserId,
enviroment: .production,
configuration: self.generateConfiguration(),
delegate: self) { isSuccess in
if isSuccess {
print("### SDK initailzed")
}
}
}
}
// MARK: Wishi Client SDK Delegate Methods
func presented(viewController: UIViewController) {
print("### viewController \(viewController)")
}
func sdkFailure(error: SDKError) {
print("### error \(error)")
}
func itemsSelected(fromController controller: WishiSDK.QuizViewController,
quizObject: WishiSDK.WSQuiz,
selectedOptions: [WishiSDK.WSQuizAnswer],
lastSelectedOption: WishiSDK.WSQuizAnswer) {
}
func screenSelectionDone(fromController controller: QuizViewController,
quizObject: WSQuiz,
selectedOptions: [WSQuizAnswer]) {
}
func onItemClick(url: String) {
print(url)
}
func onReadMessages(unreadMessage: Int) {
print("### Unread Message: \(unreadMessage)")
}
func getConfiguration() -> [ConfigurationStyle: Any] {
let configDictionary: [ConfigurationStyle: Any] = [ .rateTextiewFont: UIFont.systemFont(ofSize: 16.0),
.ratePlaceholderFont: UIFont.systemFont(ofSize: 16.0),
.lookViewPriceFont: UIFont.systemFont(ofSize: 16.0),
.itemViewPriceFont: UIFont.systemFont(ofSize: 16.0),
.matchReviewCellNameFont: UIFont.systemFont(ofSize: 16.0),
.matchReviewCellTextFont: UIFont.systemFont(ofSize: 16.0),
.matchInfoCellTitleFont: UIFont.systemFont(ofSize: 16.0),
.matchExpertCityNameFont: UIFont.systemFont(ofSize: 16.0),
.matchActivityIndicatorFont: UIFont.systemFont(ofSize: 16.0),
.quizAnswerUnselectedFont: UIFont.systemFont(ofSize: 16.0),
.rateDoneButtonFont: UIFont.boldSystemFont(ofSize: 16.0),
.chatLoveItReStyleItFont: UIFont.boldSystemFont(ofSize: 16.0),
.lookViewNameFont: UIFont.boldSystemFont(ofSize: 16.0),
.itemViewNameFont: UIFont.boldSystemFont(ofSize: 16.0),
.matchReviewCellTitleFont: UIFont.boldSystemFont(ofSize: 16.0),
.matchInfoCellHeaderFont: UIFont.boldSystemFont(ofSize: 16.0),
.matchExpertNameFont: UIFont.boldSystemFont(ofSize: 16.0),
.uploadPhotoButtonFont: UIFont.boldSystemFont(ofSize: 16.0),
.quizAnswerSelectedFont: UIFont.boldSystemFont(ofSize: 16.0),
.navigationTitleFont: UIFont.boldSystemFont(ofSize: 16.0),
.navigationSubTitleFont: UIFont.systemFont(ofSize: 14.0),
.rateTitleFont: UIFont.systemFont(ofSize: 22.0),
.quizButtonFont: UIFont.systemFont(ofSize: 16.0),
.rateAnswerTextCellFont: UIFont.systemFont(ofSize: 16.0),
.matchLooksCellTitleFont: UIFont.systemFont(ofSize: 22.0),
.historyProductsSectionHeaderFont: UIFont.systemFont(ofSize: 16.0),
.quizHeaderFont: UIFont.systemFont(ofSize: 22.0),
.quizSubHeaderFont: UIFont.systemFont(ofSize: 16.0),
.tooltipTitleFont: UIFont.systemFont(ofSize: 14.0),
.chatMessageTimestempFont: UIFont.systemFont(ofSize: 14.0),
.itemViewReviseItFont: UIFont.boldSystemFont(ofSize: 16.0),
.chatSectionHeaderFont: UIFont.systemFont(ofSize: 14.0),
.navigationTitleColor: UIColor.black,
.historyProductsSectionHeaderColor: UIColor.black,
.rateUnderscoreViewColor: UIColor.black,
.navigationSubTitleColor: UIColor.black,
.quizSubHeaderColor: UIColor.black,
.quizHeaderColor: UIColor.black,
.quizButtonColor: UIColor.black,
.matchLookCellBorderColor: UIColor.white,
.quizBorderUnselectedColor: UIColor.lightGray,
.uploadBackgroundColor: UIColor.darkGray,
.rateTextiewColor: UIColor.black,
.matchReviewCellNameColor: UIColor.black,
.matchReviewCellTitleColor: UIColor.black,
.matchReviewCellTextColor: UIColor.black,
.quizBorderSelectedColor: UIColor.black,
.quizAnswerLabelColor: UIColor.black,
.matchLooksCellTitleColor: UIColor.black,
.matchInfoCellHeaderColor: UIColor.black,
.matchInfoCellTitleColor: UIColor.black,
.uploadPhotoButtonColor: UIColor.black,
.matchExpertNameColor: UIColor.black,
.matchExpertCityNameColor: UIColor.black,
.matchActivityIndicatorColor: UIColor.black,
.quizButtonTextColor: UIColor.white
]
return configDictionary
}
Last updated