diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2021-05-13 13:49:33 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2021-05-13 13:49:33 -0400 |
commit | 7f04afd1dad688c010e5304bb80d10b078848222 (patch) | |
tree | 7d552d16548b869399b13d4d99dd67127f0a28c7 /Example Apps | |
parent | 42b7b1fb55aaa8abedb050d9f95a005ed69caaff (diff) | |
download | sdl_ios-7f04afd1dad688c010e5304bb80d10b078848222.tar.gz |
Refactor Obj-C example app connection process to mirror Swift ap
Diffstat (limited to 'Example Apps')
-rw-r--r-- | Example Apps/Example ObjC/ConnectionTCPTableViewController.m | 4 | ||||
-rw-r--r-- | Example Apps/Example ObjC/ProxyManager.m | 30 | ||||
-rw-r--r-- | Example Apps/Example Swift/ProxyManager.swift | 7 |
3 files changed, 19 insertions, 22 deletions
diff --git a/Example Apps/Example ObjC/ConnectionTCPTableViewController.m b/Example Apps/Example ObjC/ConnectionTCPTableViewController.m index c062d5106..3ca9a78a0 100644 --- a/Example Apps/Example ObjC/ConnectionTCPTableViewController.m +++ b/Example Apps/Example ObjC/ConnectionTCPTableViewController.m @@ -72,9 +72,7 @@ #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - if (indexPath.section != 0) { - return; - } + if (indexPath.section != 0) { return; } switch (indexPath.row) { case 0: { diff --git a/Example Apps/Example ObjC/ProxyManager.m b/Example Apps/Example ObjC/ProxyManager.m index 06ab5dd02..9a4fa1808 100644 --- a/Example Apps/Example ObjC/ProxyManager.m +++ b/Example Apps/Example ObjC/ProxyManager.m @@ -99,29 +99,27 @@ NS_ASSUME_NONNULL_BEGIN - (void)startWithProxyTransportType:(ProxyTransportType)proxyTransportType { [self sdlex_updateProxyState:ProxyStateSearchingForConnection]; - SDLLifecycleConfiguration *lifecycleConfig = proxyTransportType == ProxyTransportTypeIAP ? [self.class sdlex_iapLifecycleConfiguration] : [self.class sdlex_tcpLifecycleConfiguration]; - [self sdlex_setupConfigurationWithLifecycleConfiguration:lifecycleConfig]; + SDLConfiguration *config = (proxyTransportType == ProxyTransportTypeIAP) ? [self.class sdlex_iapConfiguration] : [self.class sdlex_tcpConfiguration]; + self.sdlManager = [[SDLManager alloc] initWithConfiguration:config delegate:self]; + [self sdlex_startManager]; } -+ (SDLLifecycleConfiguration *)sdlex_iapLifecycleConfiguration { - return [self.class sdlex_setLifecycleConfigurationPropertiesOnConfiguration:[SDLLifecycleConfiguration defaultConfigurationWithAppName:ExampleAppName fullAppId:ExampleFullAppId]]; -} ++ (SDLConfiguration *)sdlex_iapConfiguration { + SDLLifecycleConfiguration *lifecycleConfig = [self.class sdlex_setLifecycleConfigurationPropertiesOnConfiguration:[SDLLifecycleConfiguration defaultConfigurationWithAppName:ExampleAppName fullAppId:ExampleFullAppId]]; -+ (SDLLifecycleConfiguration *)sdlex_tcpLifecycleConfiguration { - return [self.class sdlex_setLifecycleConfigurationPropertiesOnConfiguration:[SDLLifecycleConfiguration debugConfigurationWithAppName:ExampleAppName fullAppId:ExampleFullAppId ipAddress:[Preferences sharedPreferences].ipAddress port:[Preferences sharedPreferences].port]]; + return [self sdlex_setupManagerConfigurationWithLifecycleConfiguration:lifecycleConfig]; } -- (void)sdlex_setupConfigurationWithLifecycleConfiguration:(SDLLifecycleConfiguration *)lifecycleConfiguration { - if (self.sdlManager != nil) { - // Manager already created, just start it again. - [self sdlex_startManager]; - return; - } ++ (SDLConfiguration *)sdlex_tcpConfiguration { + SDLLifecycleConfiguration *lifecycleConfig = [self.class sdlex_setLifecycleConfigurationPropertiesOnConfiguration:[SDLLifecycleConfiguration debugConfigurationWithAppName:ExampleAppName fullAppId:ExampleFullAppId ipAddress:[Preferences sharedPreferences].ipAddress port:[Preferences sharedPreferences].port]]; + return [self sdlex_setupManagerConfigurationWithLifecycleConfiguration:lifecycleConfig]; +} + ++ (SDLConfiguration *)sdlex_setupManagerConfigurationWithLifecycleConfiguration:(SDLLifecycleConfiguration *)lifecycleConfiguration { SDLLockScreenConfiguration *lockScreenConfiguration = [SDLLockScreenConfiguration enabledConfigurationWithAppIcon:[UIImage imageNamed:ExampleAppLogoName] backgroundColor:nil]; - SDLConfiguration *config = [[SDLConfiguration alloc] initWithLifecycle:lifecycleConfiguration lockScreen:lockScreenConfiguration logging:[self.class sdlex_logConfiguration] fileManager:[SDLFileManagerConfiguration defaultConfiguration] encryption:[SDLEncryptionConfiguration defaultConfiguration]]; - self.sdlManager = [[SDLManager alloc] initWithConfiguration:config delegate:self]; - [self sdlex_startManager]; + + return [[SDLConfiguration alloc] initWithLifecycle:lifecycleConfiguration lockScreen:lockScreenConfiguration logging:[self.class sdlex_logConfiguration] fileManager:[SDLFileManagerConfiguration defaultConfiguration] encryption:[SDLEncryptionConfiguration defaultConfiguration]]; } + (SDLLifecycleConfiguration *)sdlex_setLifecycleConfigurationPropertiesOnConfiguration:(SDLLifecycleConfiguration *)config { diff --git a/Example Apps/Example Swift/ProxyManager.swift b/Example Apps/Example Swift/ProxyManager.swift index 9cbee5d6b..52f1933d1 100644 --- a/Example Apps/Example Swift/ProxyManager.swift +++ b/Example Apps/Example Swift/ProxyManager.swift @@ -46,7 +46,8 @@ extension ProxyManager { /// - Parameter connectionType: The type of transport layer to use. func start(with proxyTransportType: ProxyTransportType) { delegate?.didChangeProxyState(ProxyState.searching) - sdlManager = SDLManager(configuration: proxyTransportType == .iap ? ProxyManager.connectIAP() : ProxyManager.connectTCP(), delegate: self) + + sdlManager = SDLManager(configuration: (proxyTransportType == .iap) ? ProxyManager.iapConfiguration : ProxyManager.tcpConfiguration, delegate: self) startManager() } @@ -71,7 +72,7 @@ private extension ProxyManager { /// Configures an iAP transport layer. /// /// - Returns: A SDLConfiguration object - class func connectIAP() -> SDLConfiguration { + class var iapConfiguration: SDLConfiguration { let lifecycleConfiguration = SDLLifecycleConfiguration(appName: ExampleAppName, fullAppId: ExampleFullAppId) return setupManagerConfiguration(with: lifecycleConfiguration) } @@ -79,7 +80,7 @@ private extension ProxyManager { /// Configures a TCP transport layer with the IP address and port of the remote SDL Core instance. /// /// - Returns: A SDLConfiguration object - class func connectTCP() -> SDLConfiguration { + class var tcpConfiguration: SDLConfiguration { let lifecycleConfiguration = SDLLifecycleConfiguration(appName: ExampleAppName, fullAppId: ExampleFullAppId, ipAddress: AppUserDefaults.shared.ipAddress!, port: UInt16(AppUserDefaults.shared.port!)!) return setupManagerConfiguration(with: lifecycleConfiguration) } |