AccountSetupController.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. //
  2. // AccountSetupController.swift
  3. // deltachat-ios
  4. //
  5. // Created by Bastian van de Wetering on 02.04.19.
  6. // Copyright © 2019 Jonas Reinsch. All rights reserved.
  7. //
  8. import SafariServices
  9. import UIKit
  10. class AccountSetupController: UITableViewController {
  11. weak var coordinator: AccountSetupCoordinator?
  12. private var backupProgressObserver: Any?
  13. private var configureProgressObserver: Any?
  14. private var oauth2Observer: Any?
  15. private lazy var hudHandler: HudHandler = {
  16. let hudHandler = HudHandler(parentView: self.tableView)
  17. return hudHandler
  18. }()
  19. private lazy var emailCell: TextFieldCell = {
  20. let cell = TextFieldCell.makeEmailCell(delegate: self)
  21. cell.textField.tag = 0
  22. cell.textField.accessibilityIdentifier = "emailTextField" // will be used to eventually show oAuth-Dialogue when pressing return key
  23. cell.setText(text: MRConfig.addr ?? nil)
  24. return cell
  25. }()
  26. private lazy var passwordCell: TextFieldCell = {
  27. let cell = TextFieldCell.makePasswordCell(delegate: self)
  28. cell.textField.tag = 1
  29. cell.accessibilityIdentifier = "passwordCell" // will be used to eventually show oAuth-Dialogue when selecting
  30. cell.setText(text: MRConfig.mailPw ?? nil)
  31. return cell
  32. }()
  33. private lazy var restoreCell: ActionCell = {
  34. let cell = ActionCell(frame: .zero)
  35. cell.actionTitle = "Restore from backup"
  36. cell.accessibilityIdentifier = "restoreCell"
  37. return cell
  38. }()
  39. lazy var imapServerCell: TextFieldCell = {
  40. let cell = TextFieldCell(description: "IMAP Server", placeholder: MRConfig.mailServer ?? MRConfig.configuredMailServer, delegate: self)
  41. cell.accessibilityIdentifier = "IMAPServerCell"
  42. cell.textField.tag = 2
  43. return cell
  44. }()
  45. lazy var imapUserCell: TextFieldCell = {
  46. let cell = TextFieldCell(description: "IMAP User", placeholder: MRConfig.mailUser ?? MRConfig.configuredMailUser, delegate: self)
  47. cell.accessibilityIdentifier = "IMAPUserCell"
  48. cell.textField.tag = 3
  49. return cell
  50. }()
  51. lazy var imapPortCell: UITableViewCell = {
  52. let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
  53. cell.textLabel?.text = "IMAP Port"
  54. cell.accessoryType = .disclosureIndicator
  55. cell.detailTextLabel?.text = MRConfig.mailPort ?? MRConfig.configuredMailPort
  56. cell.accessibilityIdentifier = "IMAPPortCell"
  57. return cell
  58. }()
  59. lazy var imapSecurityCell: TextFieldCell = {
  60. let text = "\(MRConfig.getImapSecurity())"
  61. let cell = TextFieldCell(description: "IMAP Security", placeholder: text, delegate: self)
  62. cell.accessibilityIdentifier = "IMAPSecurityCell"
  63. cell.textField.tag = 5
  64. cell.textField.keyboardType = UIKeyboardType.numberPad
  65. return cell
  66. }()
  67. lazy var smtpServerCell: TextFieldCell = {
  68. let cell = TextFieldCell(description: "SMTP Server", placeholder: MRConfig.sendServer ?? MRConfig.configuredSendServer, delegate: self)
  69. cell.accessibilityIdentifier = "SMTPServerCell"
  70. cell.textField.tag = 6
  71. return cell
  72. }()
  73. lazy var smtpUserCell: TextFieldCell = {
  74. let cell = TextFieldCell(description: "SMTP User", placeholder: MRConfig.sendUser ?? MRConfig.configuredSendUser, delegate: self)
  75. cell.accessibilityIdentifier = "SMTPUserCell"
  76. cell.textField.tag = 7
  77. return cell
  78. }()
  79. lazy var smtpPortCell: TextFieldCell = {
  80. let cell = TextFieldCell(description: "SMTP Port", placeholder: MRConfig.sendPort ?? MRConfig.configuredSendPort, delegate: self)
  81. cell.accessibilityIdentifier = "SMTPPortCell"
  82. cell.textField.tag = 8
  83. return cell
  84. }()
  85. lazy var smtpPasswordCell: TextFieldCell = {
  86. let cell = TextFieldCell(description: "SMTP Password", placeholder: "*************", delegate: self)
  87. cell.accessibilityIdentifier = "SMTPPasswordCell"
  88. cell.textField.tag = 9
  89. return cell
  90. }()
  91. lazy var smtpSecurityCell: TextFieldCell = {
  92. let text = "\(MRConfig.getSmtpSecurity())"
  93. let cell = TextFieldCell(description: "SMTP Security", placeholder: text, delegate: self)
  94. cell.accessibilityIdentifier = "SMTPSecurityCell"
  95. cell.textField.tag = 10
  96. cell.textField.keyboardType = UIKeyboardType.numberPad
  97. return cell
  98. }()
  99. // this loginButton can be enabled and disabled
  100. let loginButton: UIBarButtonItem = UIBarButtonItem(title: "Login", style: .done, target: self, action: #selector(loginButtonPressed))
  101. private lazy var basicSectionCells: [UITableViewCell] = [emailCell, passwordCell]
  102. private lazy var restoreCells: [UITableViewCell] = [restoreCell]
  103. private lazy var advancedSectionCells: [UITableViewCell] = [
  104. imapServerCell,
  105. imapUserCell,
  106. imapPortCell,
  107. imapSecurityCell,
  108. smtpServerCell,
  109. smtpUserCell,
  110. smtpPortCell,
  111. smtpPasswordCell,
  112. smtpSecurityCell,
  113. ]
  114. private var advancedSectionShowing: Bool = false
  115. init() {
  116. super.init(style: .grouped)
  117. hidesBottomBarWhenPushed = true
  118. }
  119. required init?(coder _: NSCoder) {
  120. fatalError("init(coder:) has not been implemented")
  121. }
  122. override func viewDidLoad() {
  123. super.viewDidLoad()
  124. title = "Login to your server"
  125. // navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Close", style: .plain, target: self, action: #selector(closeButtonPressed))
  126. navigationItem.rightBarButtonItem = loginButton
  127. }
  128. override func viewDidAppear(_ animated: Bool) {
  129. super.viewDidAppear(animated)
  130. addProgressHudEventListener()
  131. // loginButton.isEnabled = false
  132. }
  133. override func viewDidDisappear(_: Bool) {
  134. let nc = NotificationCenter.default
  135. if let backupProgressObserver = self.backupProgressObserver {
  136. nc.removeObserver(backupProgressObserver)
  137. }
  138. if let configureProgressObserver = self.configureProgressObserver {
  139. nc.removeObserver(configureProgressObserver)
  140. }
  141. if let oauth2Observer = self.oauth2Observer {
  142. nc.removeObserver(oauth2Observer)
  143. }
  144. }
  145. // MARK: - Table view data source
  146. override func numberOfSections(in _: UITableView) -> Int {
  147. // #warning Incomplete implementation, return the number of sections
  148. return 3
  149. }
  150. override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
  151. // #warning Incomplete implementation, return the number of rows
  152. if section == 0 {
  153. return basicSectionCells.count
  154. } else if section == 1 {
  155. return restoreCells.count
  156. } else {
  157. return advancedSectionShowing ? advancedSectionCells.count : 0
  158. }
  159. }
  160. override func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
  161. if section == 2 {
  162. return "Advanced"
  163. } else {
  164. return nil
  165. }
  166. }
  167. override func tableView(_: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  168. if section == 2 {
  169. // Advanced Header
  170. let advancedView = AdvancedSectionHeader()
  171. advancedView.handleTap = toggleAdvancedSection
  172. // set tapHandler
  173. return advancedView
  174. } else {
  175. return nil
  176. }
  177. }
  178. override func tableView(_: UITableView, heightForHeaderInSection _: Int) -> CGFloat {
  179. return 36.0
  180. }
  181. override func tableView(_: UITableView, titleForFooterInSection section: Int) -> String? {
  182. if section == 0 {
  183. return "There are no Delta Chat servers, your data stays on your device!"
  184. } else if section == 2 {
  185. return "For known email providers additional settings are setup automatically. Sometimes IMAP needs to be enabled in the web frontend. Consult your email provider or friends for help"
  186. } else {
  187. return nil
  188. }
  189. }
  190. override func tableView(_: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  191. let section = indexPath.section
  192. let row = indexPath.row
  193. if section == 0 {
  194. // basicSection
  195. return basicSectionCells[row]
  196. } else if section == 1 {
  197. return restoreCells[row]
  198. } else {
  199. // advancedSection
  200. return advancedSectionCells[row]
  201. }
  202. }
  203. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  204. guard let tappedCell = tableView.cellForRow(at: indexPath) else { return }
  205. // handle tap on password -> show oAuthDialogue
  206. if let textFieldCell = tappedCell as? TextFieldCell {
  207. if textFieldCell.accessibilityIdentifier == "passwordCell" {
  208. if let emailAdress = textFieldCell.getText() {
  209. _ = showOAuthAlertIfNeeded(emailAddress: emailAdress, handleCancel: nil)
  210. }
  211. }
  212. }
  213. if tappedCell.accessibilityIdentifier == "restoreCell" {
  214. restoreBackup()
  215. }
  216. }
  217. private func toggleAdvancedSection(button: UILabel) {
  218. let willShow = !advancedSectionShowing
  219. // extract indexPaths from advancedCells
  220. let advancedIndexPaths: [IndexPath] = advancedSectionCells.indices.map { IndexPath(row: $0, section: 2) }
  221. // advancedSectionCells.indices.map({indexPaths.append(IndexPath(row: $0, section: 1))}
  222. // set flag before delete/insert operation, because cellForRowAt will be triggered and uses this flag
  223. advancedSectionShowing = willShow
  224. button.text = willShow ? "Hide" : "Show"
  225. if willShow {
  226. tableView.insertRows(at: advancedIndexPaths, with: .fade)
  227. } else {
  228. tableView.deleteRows(at: advancedIndexPaths, with: .fade)
  229. }
  230. }
  231. @objc private func loginButtonPressed() {
  232. guard let emailAddress = emailCell.getText() else {
  233. return // handle case when either email or pw fields are empty
  234. }
  235. let oAuthStarted = showOAuthAlertIfNeeded(emailAddress: emailAddress, handleCancel: loginButtonPressed) // if canceled we will run this method again but this time oAuthStarted will be false
  236. if oAuthStarted {
  237. // the loginFlow will be handled by oAuth2
  238. return
  239. }
  240. let password = passwordCell.getText() ?? "" // empty passwords are ok -> for oauth there is no password needed
  241. login(emailAddress: emailAddress, password: password)
  242. }
  243. private func login(emailAddress: String, password: String, skipAdvanceSetup: Bool = false) {
  244. MRConfig.addr = emailAddress
  245. MRConfig.mailPw = password
  246. if !skipAdvanceSetup {
  247. evaluluateAdvancedSetup() // this will set MRConfig related to advanced fields
  248. }
  249. dc_configure(mailboxPointer)
  250. hudHandler.showBackupHud("Configuring account")
  251. }
  252. @objc func closeButtonPressed() {
  253. dismiss(animated: true, completion: nil)
  254. }
  255. // returns true if needed
  256. private func showOAuthAlertIfNeeded(emailAddress: String, handleCancel: (() -> Void)?) -> Bool {
  257. if MRConfig.getAuthFlags() == 4 {
  258. // user has previously denied oAuth2-setup
  259. return false
  260. }
  261. guard let oAuth2UrlPointer = dc_get_oauth2_url(mailboxPointer, emailAddress, "chat.delta:/auth") else {
  262. return false
  263. }
  264. let oAuth2Url = String(cString: oAuth2UrlPointer)
  265. if let url = URL(string: oAuth2Url) {
  266. let title = "Continue with simplified setup"
  267. // swiftlint:disable all
  268. let message = "The entered e-mail address supports a simplified setup (oAuth2).\n\nIn the next step, please allow Delta Chat to act as your Chat with E-Mail app.\n\nThere are no Delta Chat servers, your data stays on your device."
  269. let oAuthAlertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
  270. let confirm = UIAlertAction(title: "Confirm", style: .default, handler: {
  271. [unowned self] _ in
  272. let nc = NotificationCenter.default
  273. self.oauth2Observer = nc.addObserver(self, selector: #selector(self.oauthLoginApproved), name: NSNotification.Name("oauthLoginApproved"), object: nil)
  274. self.launchOAuthBrowserWindow(url: url)
  275. })
  276. let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: {
  277. _ in
  278. MRConfig.setAuthFlags(flags: Int(DC_LP_AUTH_NORMAL))
  279. handleCancel?()
  280. })
  281. oAuthAlertController.addAction(confirm)
  282. oAuthAlertController.addAction(cancel)
  283. present(oAuthAlertController, animated: true, completion: nil)
  284. return true
  285. } else {
  286. return false
  287. }
  288. }
  289. @objc func oauthLoginApproved(notification: Notification) {
  290. guard let userInfo = notification.userInfo, let token = userInfo["token"] as? String, let emailAddress = emailCell.getText() else {
  291. return
  292. }
  293. passwordCell.setText(text: token)
  294. MRConfig.setAuthFlags(flags: Int(DC_LP_AUTH_OAUTH2))
  295. login(emailAddress: emailAddress, password: token, skipAdvanceSetup: true)
  296. }
  297. private func launchOAuthBrowserWindow(url: URL) {
  298. UIApplication.shared.open(url) // this opens safari as seperate app
  299. }
  300. private func addProgressHudEventListener() {
  301. let nc = NotificationCenter.default
  302. backupProgressObserver = nc.addObserver(
  303. forName: dcNotificationBackupProgress,
  304. object: nil,
  305. queue: nil
  306. ) {
  307. notification in
  308. if let ui = notification.userInfo {
  309. if ui["error"] as! Bool {
  310. self.hudHandler.setHudError(ui["errorMessage"] as? String)
  311. } else if ui["done"] as! Bool {
  312. self.hudHandler.setHudDone(callback: self.handleLoginSuccess)
  313. } else {
  314. self.hudHandler.setHudProgress(ui["progress"] as! Int)
  315. }
  316. }
  317. }
  318. configureProgressObserver = nc.addObserver(
  319. forName: dcNotificationConfigureProgress,
  320. object: nil,
  321. queue: nil
  322. ) {
  323. notification in
  324. if let ui = notification.userInfo {
  325. if ui["error"] as! Bool {
  326. self.hudHandler.setHudError(ui["errorMessage"] as? String)
  327. } else if ui["done"] as! Bool {
  328. self.hudHandler.setHudDone(callback: self.handleLoginSuccess)
  329. } else {
  330. self.hudHandler.setHudProgress(ui["progress"] as! Int)
  331. }
  332. }
  333. }
  334. }
  335. private func evaluluateAdvancedSetup() {
  336. for cell in advancedSectionCells {
  337. if let textFieldCell = cell as? TextFieldCell {
  338. switch cell.accessibilityIdentifier {
  339. case "IMAPServerCell":
  340. MRConfig.mailServer = textFieldCell.getText() ?? nil
  341. case "IMAPUserCell":
  342. MRConfig.mailUser = textFieldCell.getText() ?? nil
  343. case "IMAPPortCell":
  344. MRConfig.mailPort = textFieldCell.getText() ?? nil
  345. case "IMAPSecurityCell":
  346. let flag = 0
  347. MRConfig.setImapSecurity(imapFlags: flag)
  348. case "SMTPServerCell":
  349. MRConfig.sendServer = textFieldCell.getText() ?? nil
  350. case "SMTPSUserCell":
  351. MRConfig.sendUser = textFieldCell.getText() ?? nil
  352. case "SMTPPortCell":
  353. MRConfig.sendPort = textFieldCell.getText() ?? nil
  354. case "SMTPPasswordCell":
  355. MRConfig.sendPw = textFieldCell.getText() ?? nil
  356. case "SMTPSecurityCell":
  357. let flag = 0
  358. MRConfig.setSmtpSecurity(smptpFlags: flag)
  359. default:
  360. logger.info("unknown identifier", cell.accessibilityIdentifier ?? "")
  361. }
  362. }
  363. }
  364. }
  365. private func restoreBackup() {
  366. logger.info("restoring backup")
  367. if MRConfig.configured {
  368. return
  369. }
  370. let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
  371. if !documents.isEmpty {
  372. logger.info("looking for backup in: \(documents[0])")
  373. if let file = dc_imex_has_backup(mailboxPointer, documents[0]) {
  374. logger.info("restoring backup: \(String(cString: file))")
  375. hudHandler.showBackupHud("Restoring Backup")
  376. dc_imex(mailboxPointer, DC_IMEX_IMPORT_BACKUP, file, nil)
  377. return
  378. }
  379. let alert = UIAlertController(title: "Can not restore", message: "No Backup found", preferredStyle: .alert)
  380. alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { _ in
  381. }))
  382. present(alert, animated: true, completion: nil)
  383. return
  384. }
  385. logger.error("no documents directory found")
  386. }
  387. private func handleLoginSuccess() {
  388. // used when login hud successfully went trough
  389. dismiss(animated: true, completion: nil)
  390. }
  391. }
  392. extension AccountSetupController: UITextFieldDelegate {
  393. func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  394. let currentTag = textField.tag
  395. if textField.accessibilityIdentifier == "emailTextField", showOAuthAlertIfNeeded(emailAddress: textField.text ?? "", handleCancel: {
  396. self.passwordCell.textField.becomeFirstResponder()
  397. }) {
  398. // all the action is defined in if condition
  399. } else {
  400. if let nextField = tableView.viewWithTag(currentTag + 1) as? UITextField {
  401. if nextField.tag > 1, !advancedSectionShowing {
  402. // gets here when trying to activate a collapsed cell
  403. return false
  404. }
  405. nextField.becomeFirstResponder()
  406. }
  407. }
  408. return false
  409. }
  410. }
  411. class AdvancedSectionHeader: UIView {
  412. var handleTap: ((UILabel) -> Void)?
  413. private var label: UILabel = {
  414. let label = UILabel()
  415. label.text = "ADVANCED"
  416. label.font = UIFont.systemFont(ofSize: 15)
  417. label.textColor = UIColor.darkGray
  418. return label
  419. }()
  420. /*
  421. why UILabel, why no UIButton? For unknown reasons UIButton's target function was not triggered when one of the textfields in the tableview was active -> used label as workaround
  422. */
  423. private lazy var toggleButton: UILabel = {
  424. let label = UILabel()
  425. label.text = "Show"
  426. label.font = UIFont.systemFont(ofSize: 15, weight: .medium)
  427. label.textColor = UIColor.systemBlue
  428. return label
  429. }()
  430. //
  431. // private var toggleButton:UIButton = {
  432. // let button = UIButton(type: .system)
  433. // button.setTitle("Show", for: .normal)
  434. // button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside )
  435. // //button.target(forAction: #selector(buttonTapped(_:)), withSender: self)
  436. // return button
  437. // }()
  438. init() {
  439. super.init(frame: .zero) // will be constraint from tableViewDelegate
  440. setupSubviews()
  441. let tap = UITapGestureRecognizer(target: self, action: #selector(viewTapped)) // use this if the whole header is supposed to be clickable
  442. addGestureRecognizer(tap)
  443. }
  444. required init?(coder _: NSCoder) {
  445. fatalError("init(coder:) has not been implemented")
  446. }
  447. func setupSubviews() {
  448. addSubview(label)
  449. label.translatesAutoresizingMaskIntoConstraints = false
  450. label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 15).isActive = true
  451. label.centerYAnchor.constraint(equalTo: centerYAnchor, constant: 0).isActive = true
  452. addSubview(toggleButton)
  453. toggleButton.translatesAutoresizingMaskIntoConstraints = false
  454. toggleButton.leadingAnchor.constraint(equalTo: trailingAnchor, constant: -60).isActive = true // since button will change title it should be left aligned
  455. toggleButton.centerYAnchor.constraint(equalTo: label.centerYAnchor, constant: 0).isActive = true
  456. }
  457. @objc func buttonTapped(_: UIButton) {
  458. // handleTap?(button)
  459. }
  460. @objc func viewTapped() {
  461. handleTap?(toggleButton)
  462. }
  463. }
  464. /*
  465. class InputTableViewCell: UITableViewCell {
  466. lazy var inputField: UITextField = {
  467. let textField = UITextField()
  468. return textField
  469. }()
  470. init() {
  471. super.init(style: .default, reuseIdentifier: nil)
  472. setupView()
  473. }
  474. required init?(coder aDecoder: NSCoder) {
  475. fatalError("init(coder:) has not been implemented")
  476. }
  477. private func setupView() {
  478. contentView.addSubview(inputField)
  479. inputField.translatesAutoresizingMaskIntoConstraints = false
  480. inputField.centerYAnchor.constraint(equalTo: contentView.centerYAnchor, constant: 0).isActive = true
  481. inputField.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 5).isActive = true
  482. inputField.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -5).isActive = true
  483. inputField.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 100).isActive = true
  484. inputField.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 0).isActive = true
  485. }
  486. public func getText() -> String? {
  487. return inputField.text
  488. }
  489. }
  490. class PasswordInputCell: UITableViewCell {
  491. lazy var inputField: UITextField = {
  492. let textField = UITextField()
  493. textField.isSecureTextEntry = true
  494. return textField
  495. }()
  496. // TODO: to add Eye-icon -> uncomment -> add to inputField.rightView
  497. /*
  498. lazy var makeVisibleIcon: UIImageView = {
  499. let view = UIImageView(image: )
  500. return view
  501. }()
  502. */
  503. init() {
  504. super.init(style: .default, reuseIdentifier: nil)
  505. setupView()
  506. }
  507. required init?(coder aDecoder: NSCoder) {
  508. fatalError("init(coder:) has not been implemented")
  509. }
  510. private func setupView() {
  511. contentView.addSubview(inputField)
  512. inputField.translatesAutoresizingMaskIntoConstraints = false
  513. inputField.centerYAnchor.constraint(equalTo: contentView.centerYAnchor, constant: 0).isActive = true
  514. inputField.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 5).isActive = true
  515. inputField.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -5).isActive = true
  516. inputField.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 100).isActive = true
  517. inputField.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 0).isActive = true
  518. }
  519. public func getText() -> String? {
  520. return inputField.text
  521. }
  522. }
  523. */