Skip to content

Instantly share code, notes, and snippets.

@aataraxiaa
Created March 24, 2021 13:53
Show Gist options
  • Select an option

  • Save aataraxiaa/b5e19871a1c468e5a9037fb0fda9fb68 to your computer and use it in GitHub Desktop.

Select an option

Save aataraxiaa/b5e19871a1c468e5a9037fb0fda9fb68 to your computer and use it in GitHub Desktop.
Z1_Chat_Close_Button
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
Chat.initialize(accountKey: "", appId: "")
}
@IBAction func buttonPressed(_ sender: Any) {
if let viewController = configureChat() {
self.navigationController?.pushViewController(viewController, animated: true)
}
}
func configureChat() -> UIViewController? {
do {
let chatEngine = try ChatEngine.engine()
let viewController = try Messaging.instance.buildUI(engines: [chatEngine], configs: [ChatConfiguration()])
viewController.edgesForExtendedLayout = []
viewController.title = NSLocalizedString("Live Chat", comment: "Title String")
let button = UIBarButtonItem(title: "Close", style: .plain, target: self, action: #selector(close))
viewController.navigationItem.leftBarButtonItem = button
return viewController
} catch {
// TODO: Add an alert or an appropriate UI to show for an error scenario.
print("Unhandled Error!!")
return nil
}
}
@objc
func close() {
self.navigationController?.popViewController(animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment