diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2017-10-30 14:07:00 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2017-10-30 14:13:42 -0400 |
commit | 127709b2b83eeea322a33e1258792f8ce367a5d2 (patch) | |
tree | 1238b710bbdb686f2be28e493acbcd5aa87754b0 | |
parent | 0712928e1c190a97762f5f25ece8a99509d3797e (diff) | |
download | sdl_ios-127709b2b83eeea322a33e1258792f8ce367a5d2.tar.gz |
Merge pull request #778 from smartdevicelink/bug/issue_773_missing_protocol_string_crash
Fix missing protocol string crash (5.0)
# Conflicts:
# SmartDeviceLink/SDLIAPTransport.m
-rw-r--r-- | SmartDeviceLink/SDLIAPTransport.m | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/SmartDeviceLink/SDLIAPTransport.m b/SmartDeviceLink/SDLIAPTransport.m index 80396cd54..625d72912 100644 --- a/SmartDeviceLink/SDLIAPTransport.m +++ b/SmartDeviceLink/SDLIAPTransport.m @@ -239,7 +239,13 @@ int const streamOpenTimeoutSeconds = 2; - (BOOL)sdl_connectAccessory:(EAAccessory *)accessory { BOOL connecting = NO; - + + if ([self.class sdl_supportsRequiredProtocolStrings] != nil) { + NSString *failedString = [self.class sdl_supportsRequiredProtocolStrings]; + NSAssert(NO, @"Some SDL protocol strings are not supported, check the README for all strings that must be included in your info.plist file. Missing string: %@", failedString); + return connecting; + } + if ([accessory supportsProtocol:multiSessionProtocolString] && SDL_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9")) { [self sdl_createIAPDataSessionWithAccessory:accessory forProtocol:multiSessionProtocolString]; connecting = YES; @@ -254,6 +260,32 @@ int const streamOpenTimeoutSeconds = 2; return connecting; } +/** + Check all required protocol strings in the info.plist dictionary. + + @return A missing protocol string or nil if all strings are supported. + */ ++ (nullable NSString *)sdl_supportsRequiredProtocolStrings { + NSArray<NSString *> *protocolStrings = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedExternalAccessoryProtocols"]; + + if (![protocolStrings containsObject:multiSessionProtocolString]) { + return multiSessionProtocolString; + } + + if (![protocolStrings containsObject:legacyProtocolString]) { + return legacyProtocolString; + } + + for (int i = 0; i < 30; i++) { + NSString *indexedProtocolString = [NSString stringWithFormat:@"%@%i", indexedProtocolStringPrefix, i]; + if (![protocolStrings containsObject:indexedProtocolString]) { + return indexedProtocolString; + } + } + + return nil; +} + - (void)sdl_establishSessionWithAccessory:(EAAccessory *)accessory { [SDLDebugTool logInfo:@"Attempting To Connect"]; if (self.retryCounter < createSessionRetries) { @@ -266,6 +298,12 @@ int const streamOpenTimeoutSeconds = 2; return; } + if ([self.class sdl_supportsRequiredProtocolStrings] != nil) { + NSString *failedString = [self.class sdl_supportsRequiredProtocolStrings]; + NSAssert(NO, @"Some SDL protocol strings are not supported, check the README for all strings that must be included in your info.plist file. Missing string: %@", failedString); + return; + } + // Determine if we can start a multi-app session or a legacy (single-app) session if ((sdlAccessory = [EAAccessoryManager findAccessoryForProtocol:multiSessionProtocolString]) && SDL_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9")) { [self sdl_createIAPDataSessionWithAccessory:sdlAccessory forProtocol:multiSessionProtocolString]; |