summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2019-05-03 10:49:45 -0400
committerGitHub <noreply@github.com>2019-05-03 10:49:45 -0400
commit7c28d635fb99594ba401e32a28e6c067513098b3 (patch)
tree85b9f896713367c719aaa6aac7329b1ff3428a62
parent1ab08e7f4aa373d4fab9ab02b86100a53ab464bc (diff)
parentf2f33e8a9c65914fdf5ee683918ab0f3590dc29d (diff)
downloadsdl_ios-7c28d635fb99594ba401e32a28e6c067513098b3.tar.gz
Merge pull request #1244 from smartdevicelink/bugfix/issue_1243_swift_example_autoreconnect
Fix auto-reconnect / manual disconnect of example apps
-rw-r--r--Example Apps/Example ObjC/ConnectionIAPTableViewController.m7
-rw-r--r--Example Apps/Example ObjC/ConnectionTCPTableViewController.m4
-rw-r--r--Example Apps/Example ObjC/ProxyManager.h2
-rw-r--r--Example Apps/Example ObjC/ProxyManager.m21
-rw-r--r--Example Apps/Example Swift/ConnectionIAPTableViewController.swift12
-rw-r--r--Example Apps/Example Swift/ConnectionTCPTableViewController.swift12
-rw-r--r--Example Apps/Example Swift/ProxyManager.swift17
-rw-r--r--Example Apps/Example Swift/ProxyManagerDelegate.swift (renamed from Example Apps/Example Swift/Protocol+ProxyManagerDelegate.swift)2
-rw-r--r--Example Apps/Shared/AppConstants.m1
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj9
10 files changed, 35 insertions, 52 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 a510c79ee..525f31766 100644
--- a/Example Apps/Example ObjC/ProxyManager.m
+++ b/Example Apps/Example ObjC/ProxyManager.m
@@ -75,13 +75,9 @@ NS_ASSUME_NONNULL_BEGIN
}];
}
-- (void)reset {
- if (self.sdlManager == nil) {
- [self sdlex_updateProxyState:ProxyStateStopped];
- return;
- }
-
+- (void)stopConnection {
[self.sdlManager stop];
+ [self sdlex_updateProxyState:ProxyStateStopped];
}
- (void)sdlex_updateProxyState:(ProxyState)newState {
@@ -97,9 +93,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)startWithProxyTransportType:(ProxyTransportType)proxyTransportType {
[self sdlex_updateProxyState:ProxyStateSearchingForConnection];
- // Check for previous instance of sdlManager
- if (self.sdlManager) { return; }
-
SDLLifecycleConfiguration *lifecycleConfig = proxyTransportType == ProxyTransportTypeIAP ? [self.class sdlex_iapLifecycleConfiguration] : [self.class sdlex_tcpLifecycleConfiguration];
[self sdlex_setupConfigurationWithLifecycleConfiguration:lifecycleConfig];
}
@@ -225,13 +218,11 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - SDLManagerDelegate
- (void)managerDidDisconnect {
- [self sdlex_updateProxyState:ProxyStateStopped];
- self.firstHMILevel = SDLHMILevelNone;
-
- // If desired, automatically start searching for a new connection to Core
- if (ExampleAppShouldRestartSDLManagerOnDisconnect) {
- [self startManager];
+ if (self.state != ProxyStateStopped) {
+ [self sdlex_updateProxyState:ProxyStateSearchingForConnection];
}
+
+ self.firstHMILevel = SDLHMILevelNone;
}
- (void)hmiLevel:(SDLHMILevel)oldLevel didChangeToLevel:(SDLHMILevel)newLevel {
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 3b0ca25a4..fbedae0d5 100644
--- a/Example Apps/Example Swift/ProxyManager.swift
+++ b/Example Apps/Example Swift/ProxyManager.swift
@@ -49,13 +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(ProxyState.stopped)
+ delegate?.didChangeProxyState(.stopped)
return
}
sdlManager.stop()
+ delegate?.didChangeProxyState(.stopped)
}
}
@@ -119,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
}
@@ -141,13 +142,11 @@ private extension ProxyManager {
extension ProxyManager: SDLManagerDelegate {
/// Called when the connection beween this app and SDL Core has closed.
func managerDidDisconnect() {
- delegate?.didChangeProxyState(ProxyState.stopped)
- firstHMILevelState = .none
-
- // If desired, automatically start searching for a new connection to Core
- if ExampleAppShouldRestartSDLManagerOnDisconnect.boolValue {
- startManager()
+ if delegate?.proxyState != .some(.stopped) {
+ delegate?.didChangeProxyState(ProxyState.searching)
}
+
+ firstHMILevelState = .none
}
/// Called when the state of the SDL app has changed. The state limits the type of RPC that can be sent. Refer to the class documentation for each RPC to determine what state(s) the RPC can be sent.
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/Example Apps/Shared/AppConstants.m b/Example Apps/Shared/AppConstants.m
index c96464d63..7e81eba13 100644
--- a/Example Apps/Shared/AppConstants.m
+++ b/Example Apps/Shared/AppConstants.m
@@ -13,7 +13,6 @@ NSString * const ExampleAppName = @"SDL Example App";
NSString * const ExampleAppNameShort = @"SDL";
NSString * const ExampleAppNameTTS = @"S D L Example App";
NSString * const ExampleFullAppId = @"123e4567-e89b-12d3-a456-426655440000"; // Dummy App Id
-BOOL const ExampleAppShouldRestartSDLManagerOnDisconnect = NO;
#pragma mark - SDL Textfields
NSString * const SmartDeviceLinkText = @"SmartDeviceLink (SDL)";
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
index a5579abde..183bfcf37 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;
@@ -6699,7 +6699,6 @@
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
- English,
en,
Base,
fr,
@@ -7752,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 */,