summaryrefslogtreecommitdiff
path: root/SmartDeviceLink-ExampleSwift/ConnectionTCPTableViewController.swift
diff options
context:
space:
mode:
authorBrettyWhite <geekman3454@protonmail.com>2017-05-16 13:20:10 -0400
committerBrettyWhite <geekman3454@protonmail.com>2017-05-16 13:20:10 -0400
commit1d3a38938ca32bd6e9a768dbf1b91f1c63bf836e (patch)
treec6214c4f5d40bb3ba05259b947e27aa14f00bbbd /SmartDeviceLink-ExampleSwift/ConnectionTCPTableViewController.swift
parentdbaf4ac42a9b8aacbed406ad5246cc4d8195e65a (diff)
downloadsdl_ios-1d3a38938ca32bd6e9a768dbf1b91f1c63bf836e.tar.gz
working delegate in TCP Connection
Diffstat (limited to 'SmartDeviceLink-ExampleSwift/ConnectionTCPTableViewController.swift')
-rw-r--r--SmartDeviceLink-ExampleSwift/ConnectionTCPTableViewController.swift47
1 files changed, 28 insertions, 19 deletions
diff --git a/SmartDeviceLink-ExampleSwift/ConnectionTCPTableViewController.swift b/SmartDeviceLink-ExampleSwift/ConnectionTCPTableViewController.swift
index 00b955b2c..ec9496908 100644
--- a/SmartDeviceLink-ExampleSwift/ConnectionTCPTableViewController.swift
+++ b/SmartDeviceLink-ExampleSwift/ConnectionTCPTableViewController.swift
@@ -9,21 +9,23 @@
import UIKit
import SmartDeviceLink
-class ConnectionTCPTableViewController: UITableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
+class ConnectionTCPTableViewController: UITableViewController, UINavigationControllerDelegate, ProxyManagerDelegate {
@IBOutlet weak var ipAddressTextField: UITextField!
@IBOutlet weak var portTextField: UITextField!
@IBOutlet weak var connectTableViewCell: UITableViewCell!
@IBOutlet weak var connectButton: UIButton!
-
+
override func viewDidLoad() {
super.viewDidLoad()
+ // Set delegate to self
+ delegate = self
// Tableview setup
tableView.keyboardDismissMode = .onDrag
ipAddressTextField.text = UserDefaults.standard.string(forKey: "ipAddress")
portTextField.text = UserDefaults.standard.string(forKey: "port")
}
-
+
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
@@ -31,22 +33,29 @@ class ConnectionTCPTableViewController: UITableViewController, UIImagePickerCont
// MARK: - IBActions
@IBAction func connectButtonWasPressed(_ sender: UIButton) {
-
- }
-
- // MARK: - Table view delegate
- override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if indexPath.section != 0 {
- return
- }
- switch indexPath.row {
- case 0:
- ipAddressTextField.becomeFirstResponder()
- case 1:
- portTextField.becomeFirstResponder()
- default:
- break
- }
+ let ipAddress = ipAddressTextField.text
+ let port = portTextField.text
+
+ if (ipAddress != "" || port != ""){
+ // Save to defaults
+ UserDefaults.standard.set(ipAddress, forKey: "ipAddress")
+ UserDefaults.standard.set(port, forKey: "port")
+
+ // Initialize the SDL manager
+ _ = ProxyManager.sharedManager.connectTCP()
+
+
+ }else{
+ // Alert the user to put something in
+ let alertMessage = UIAlertController(title: "Missing Info!", message: "Make sure to set your IP Address and Port", preferredStyle: .alert)
+ alertMessage.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
+ self.present(alertMessage, animated: true, completion: nil)
+ }
+ }
+ // MARK: - Delegate Functions
+ func didChangeProxyState(_ newState: ProxyState){
+ print("UPDATE PROXY STATE CALLED \(newState)")
}
+
}