diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2019-04-23 10:42:55 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2019-04-23 10:42:55 -0400 |
commit | f2f33e8a9c65914fdf5ee683918ab0f3590dc29d (patch) | |
tree | fb10d90e910d8c90f106c86880d89829e5fe8099 | |
parent | 02ade0d7ad88d217e1088204add6c041e6e87114 (diff) | |
download | sdl_ios-bugfix/issue_1243_swift_example_autoreconnect.tar.gz |
Redo example app state logicbugfix/issue_1243_swift_example_autoreconnect
-rw-r--r-- | Example Apps/Example ObjC/ConnectionIAPTableViewController.m | 7 | ||||
-rw-r--r-- | Example Apps/Example ObjC/ConnectionTCPTableViewController.m | 4 | ||||
-rw-r--r-- | Example Apps/Example ObjC/ProxyManager.h | 2 | ||||
-rw-r--r-- | Example Apps/Example ObjC/ProxyManager.m | 7 | ||||
-rw-r--r-- | Example Apps/Example Swift/ConnectionIAPTableViewController.swift | 12 | ||||
-rw-r--r-- | Example Apps/Example Swift/ConnectionTCPTableViewController.swift | 12 | ||||
-rw-r--r-- | Example Apps/Example Swift/ProxyManager.swift | 16 | ||||
-rw-r--r-- | Example Apps/Example Swift/ProxyManagerDelegate.swift (renamed from Example Apps/Example Swift/Protocol+ProxyManagerDelegate.swift) | 2 | ||||
-rw-r--r-- | SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 8 |
9 files changed, 38 insertions, 32 deletions
diff --git a/Example Apps/Example ObjC/ConnectionIAPTableViewController.m b/Example Apps/Example ObjC/ConnectionIAPTableViewController.m index 31a0f3fdf..bfb931069 100644 --- a/Example Apps/Example ObjC/ConnectionIAPTableViewController.m +++ b/Example Apps/Example ObjC/ConnectionIAPTableViewController.m @@ -7,7 +7,6 @@ #import "ProxyManager.h" - @interface ConnectionIAPTableViewController () @property (weak, nonatomic) IBOutlet UITableViewCell *connectTableViewCell; @@ -16,9 +15,7 @@ @end - @implementation ConnectionIAPTableViewController - - (void)viewDidLoad { [super viewDidLoad]; @@ -48,10 +45,10 @@ [[ProxyManager sharedManager] startWithProxyTransportType:ProxyTransportTypeIAP]; } break; case ProxyStateSearchingForConnection: { - [[ProxyManager sharedManager] reset]; + [[ProxyManager sharedManager] stopConnection]; } break; case ProxyStateConnected: { - [[ProxyManager sharedManager] reset]; + [[ProxyManager sharedManager] stopConnection]; } break; default: break; } diff --git a/Example Apps/Example ObjC/ConnectionTCPTableViewController.m b/Example Apps/Example ObjC/ConnectionTCPTableViewController.m index e567eb44e..7b497a591 100644 --- a/Example Apps/Example ObjC/ConnectionTCPTableViewController.m +++ b/Example Apps/Example ObjC/ConnectionTCPTableViewController.m @@ -59,10 +59,10 @@ [[ProxyManager sharedManager] startWithProxyTransportType:ProxyTransportTypeTCP]; } break; case ProxyStateSearchingForConnection: { - [[ProxyManager sharedManager] reset]; + [[ProxyManager sharedManager] stopConnection]; } break; case ProxyStateConnected: { - [[ProxyManager sharedManager] reset]; + [[ProxyManager sharedManager] stopConnection]; } break; default: break; } diff --git a/Example Apps/Example ObjC/ProxyManager.h b/Example Apps/Example ObjC/ProxyManager.h index 59872b335..7226c1ac4 100644 --- a/Example Apps/Example ObjC/ProxyManager.h +++ b/Example Apps/Example ObjC/ProxyManager.h @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)sharedManager; - (void)startWithProxyTransportType:(ProxyTransportType)proxyTransportType; -- (void)reset; +- (void)stopConnection; @end diff --git a/Example Apps/Example ObjC/ProxyManager.m b/Example Apps/Example ObjC/ProxyManager.m index 448e2cf0f..525f31766 100644 --- a/Example Apps/Example ObjC/ProxyManager.m +++ b/Example Apps/Example ObjC/ProxyManager.m @@ -75,7 +75,7 @@ NS_ASSUME_NONNULL_BEGIN }]; } -- (void)reset { +- (void)stopConnection { [self.sdlManager stop]; [self sdlex_updateProxyState:ProxyStateStopped]; } @@ -218,7 +218,10 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - SDLManagerDelegate - (void)managerDidDisconnect { - [self sdlex_updateProxyState:ProxyStateSearchingForConnection]; + if (self.state != ProxyStateStopped) { + [self sdlex_updateProxyState:ProxyStateSearchingForConnection]; + } + self.firstHMILevel = SDLHMILevelNone; } diff --git a/Example Apps/Example Swift/ConnectionIAPTableViewController.swift b/Example Apps/Example Swift/ConnectionIAPTableViewController.swift index f5bacb922..5a51ad456 100644 --- a/Example Apps/Example Swift/ConnectionIAPTableViewController.swift +++ b/Example Apps/Example Swift/ConnectionIAPTableViewController.swift @@ -7,12 +7,11 @@ import UIKit class ConnectionIAPTableViewController: UITableViewController, ProxyManagerDelegate { - @IBOutlet weak var connectTableViewCell: UITableViewCell! @IBOutlet weak var table: UITableView! @IBOutlet weak var connectButton: UIButton! - var state: ProxyState = .stopped + var proxyState = ProxyState.stopped override func viewDidLoad() { super.viewDidLoad() @@ -33,19 +32,18 @@ class ConnectionIAPTableViewController: UITableViewController, ProxyManagerDeleg } // MARK: - IBActions @IBAction func connectButtonWasPressed(_ sender: UIButton) { - - switch state { + switch proxyState { case .stopped: ProxyManager.sharedManager.start(with: .iap) case .searching: - ProxyManager.sharedManager.resetConnection() + ProxyManager.sharedManager.stopConnection() case .connected: - ProxyManager.sharedManager.resetConnection() + ProxyManager.sharedManager.stopConnection() } } // MARK: - Delegate Functions func didChangeProxyState(_ newState: ProxyState) { - state = newState + proxyState = newState var newColor: UIColor? = nil var newTitle: String? = nil diff --git a/Example Apps/Example Swift/ConnectionTCPTableViewController.swift b/Example Apps/Example Swift/ConnectionTCPTableViewController.swift index 3cf1e91c3..4f07745e9 100644 --- a/Example Apps/Example Swift/ConnectionTCPTableViewController.swift +++ b/Example Apps/Example Swift/ConnectionTCPTableViewController.swift @@ -7,14 +7,13 @@ import UIKit 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! @IBOutlet weak var table: UITableView! - var state: ProxyState = .stopped + var proxyState = ProxyState.stopped override func viewDidLoad() { super.viewDidLoad() @@ -37,7 +36,6 @@ class ConnectionTCPTableViewController: UITableViewController, UINavigationContr } // MARK: - IBActions @IBAction func connectButtonWasPressed(_ sender: UIButton) { - let ipAddress = ipAddressTextField.text let port = portTextField.text @@ -45,13 +43,13 @@ class ConnectionTCPTableViewController: UITableViewController, UINavigationContr AppUserDefaults.shared.ipAddress = ipAddress AppUserDefaults.shared.port = port - switch state { + switch proxyState { case .stopped: ProxyManager.sharedManager.start(with: .tcp) case .searching: - ProxyManager.sharedManager.resetConnection() + ProxyManager.sharedManager.stopConnection() case .connected: - ProxyManager.sharedManager.resetConnection() + ProxyManager.sharedManager.stopConnection() } } else { let alertMessage = UIAlertController(title: "Missing Info!", message: "Make sure to set your IP Address and Port", preferredStyle: .alert) @@ -61,7 +59,7 @@ class ConnectionTCPTableViewController: UITableViewController, UINavigationContr } // MARK: - Delegate Functions func didChangeProxyState(_ newState: ProxyState) { - state = newState + proxyState = newState var newColor: UIColor? = nil var newTitle: String? = nil diff --git a/Example Apps/Example Swift/ProxyManager.swift b/Example Apps/Example Swift/ProxyManager.swift index ba199b543..fbedae0d5 100644 --- a/Example Apps/Example Swift/ProxyManager.swift +++ b/Example Apps/Example Swift/ProxyManager.swift @@ -49,9 +49,14 @@ extension ProxyManager { } /// Attempts to close the connection between the this app and the car's head unit. The `SDLManagerDelegate`'s `managerDidDisconnect()` is called when connection is actually closed. - func resetConnection() { + func stopConnection() { + guard sdlManager != nil else { + delegate?.didChangeProxyState(.stopped) + return + } + sdlManager.stop() - delegate?.didChangeProxyState(ProxyState.stopped) + delegate?.didChangeProxyState(.stopped) } } @@ -115,7 +120,7 @@ private extension ProxyManager { sdlManager.start(readyHandler: { [unowned self] (success, error) in guard success else { SDLLog.e("There was an error while starting up: \(String(describing: error))") - self.resetConnection() + self.stopConnection() return } @@ -137,7 +142,10 @@ private extension ProxyManager { extension ProxyManager: SDLManagerDelegate { /// Called when the connection beween this app and SDL Core has closed. func managerDidDisconnect() { - delegate?.didChangeProxyState(ProxyState.searching) + if delegate?.proxyState != .some(.stopped) { + delegate?.didChangeProxyState(ProxyState.searching) + } + firstHMILevelState = .none } diff --git a/Example Apps/Example Swift/Protocol+ProxyManagerDelegate.swift b/Example Apps/Example Swift/ProxyManagerDelegate.swift index ede7b7701..4666f9670 100644 --- a/Example Apps/Example Swift/Protocol+ProxyManagerDelegate.swift +++ b/Example Apps/Example Swift/ProxyManagerDelegate.swift @@ -9,5 +9,7 @@ import Foundation protocol ProxyManagerDelegate: class { + var proxyState: ProxyState { get } + func didChangeProxyState(_ newState: ProxyState) } diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index 0df2f3786..795fb035c 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -462,7 +462,7 @@ 5D1FF2E021304746000EB9B4 /* MenuManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1FF2D821304746000EB9B4 /* MenuManager.swift */; }; 5D1FF2E121304746000EB9B4 /* VehicleDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1FF2D921304746000EB9B4 /* VehicleDataManager.swift */; }; 5D1FF2E521304761000EB9B4 /* AppUserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1FF2E221304761000EB9B4 /* AppUserDefaults.swift */; }; - 5D1FF2E621304761000EB9B4 /* Protocol+ProxyManagerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1FF2E321304761000EB9B4 /* Protocol+ProxyManagerDelegate.swift */; }; + 5D1FF2E621304761000EB9B4 /* ProxyManagerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1FF2E321304761000EB9B4 /* ProxyManagerDelegate.swift */; }; 5D1FF2E721304761000EB9B4 /* TextValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1FF2E421304761000EB9B4 /* TextValidator.swift */; }; 5D1FF2EB2130479C000EB9B4 /* ConnectionContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1FF2E82130479C000EB9B4 /* ConnectionContainerViewController.swift */; }; 5D1FF2EC2130479C000EB9B4 /* ConnectionTCPTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1FF2E92130479C000EB9B4 /* ConnectionTCPTableViewController.swift */; }; @@ -2072,7 +2072,7 @@ 5D1FF2D821304746000EB9B4 /* MenuManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MenuManager.swift; path = "Example Apps/Example Swift/MenuManager.swift"; sourceTree = SOURCE_ROOT; }; 5D1FF2D921304746000EB9B4 /* VehicleDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = VehicleDataManager.swift; path = "Example Apps/Example Swift/VehicleDataManager.swift"; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 5D1FF2E221304761000EB9B4 /* AppUserDefaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppUserDefaults.swift; path = "Example Apps/Example Swift/AppUserDefaults.swift"; sourceTree = SOURCE_ROOT; }; - 5D1FF2E321304761000EB9B4 /* Protocol+ProxyManagerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Protocol+ProxyManagerDelegate.swift"; path = "Example Apps/Example Swift/Protocol+ProxyManagerDelegate.swift"; sourceTree = SOURCE_ROOT; }; + 5D1FF2E321304761000EB9B4 /* ProxyManagerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProxyManagerDelegate.swift; path = "Example Apps/Example Swift/ProxyManagerDelegate.swift"; sourceTree = SOURCE_ROOT; }; 5D1FF2E421304761000EB9B4 /* TextValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TextValidator.swift; path = "Example Apps/Example Swift/TextValidator.swift"; sourceTree = SOURCE_ROOT; }; 5D1FF2E82130479C000EB9B4 /* ConnectionContainerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConnectionContainerViewController.swift; path = "Example Apps/Example Swift/ConnectionContainerViewController.swift"; sourceTree = SOURCE_ROOT; }; 5D1FF2E92130479C000EB9B4 /* ConnectionTCPTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConnectionTCPTableViewController.swift; path = "Example Apps/Example Swift/ConnectionTCPTableViewController.swift"; sourceTree = SOURCE_ROOT; }; @@ -5817,7 +5817,7 @@ isa = PBXGroup; children = ( 5D1FF2E221304761000EB9B4 /* AppUserDefaults.swift */, - 5D1FF2E321304761000EB9B4 /* Protocol+ProxyManagerDelegate.swift */, + 5D1FF2E321304761000EB9B4 /* ProxyManagerDelegate.swift */, 5D1FF2E421304761000EB9B4 /* TextValidator.swift */, ); name = Utilities; @@ -7751,7 +7751,7 @@ files = ( 5D1FF2E121304746000EB9B4 /* VehicleDataManager.swift in Sources */, 5D1FF2DB21304746000EB9B4 /* ProxyManager.swift in Sources */, - 5D1FF2E621304761000EB9B4 /* Protocol+ProxyManagerDelegate.swift in Sources */, + 5D1FF2E621304761000EB9B4 /* ProxyManagerDelegate.swift in Sources */, 5D1FF2E521304761000EB9B4 /* AppUserDefaults.swift in Sources */, 5D1FF2EC2130479C000EB9B4 /* ConnectionTCPTableViewController.swift in Sources */, 5D1FF2C4213045EB000EB9B4 /* AppConstants.m in Sources */, |