From 9cf8815dce3138822bd5d13a01032d050ff056fb Mon Sep 17 00:00:00 2001 From: Srinivas Dhanwada Date: Thu, 1 Mar 2018 02:07:05 -0600 Subject: [PATCH] Fix sendData bug This commit fixes a bug that could occur when using CB transfers instead of MP. The sendData function runs at the correct time in all cases, but this is only required for MP transfers. During a CB transfer, this don't have a lasting effects, but does produce some red herring error messages. To fix this, a check was added to make sure we are performing a MP transfer before trying to send data. Issue: #67 --- PowerScout.xcodeproj/project.pbxproj | 6 ++++++ PowerScout/Bluetooth/ServiceStore.swift | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/PowerScout.xcodeproj/project.pbxproj b/PowerScout.xcodeproj/project.pbxproj index 27a2c3e..1ad0b42 100644 --- a/PowerScout.xcodeproj/project.pbxproj +++ b/PowerScout.xcodeproj/project.pbxproj @@ -1021,11 +1021,14 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = PowerScoutTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = frcteam525.PowerScoutTests; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PowerScout.app/PowerScout"; @@ -1037,11 +1040,14 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = PowerScoutTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = frcteam525.PowerScoutTests; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PowerScout.app/PowerScout"; diff --git a/PowerScout/Bluetooth/ServiceStore.swift b/PowerScout/Bluetooth/ServiceStore.swift index 1af49c4..d9839e6 100644 --- a/PowerScout/Bluetooth/ServiceStore.swift +++ b/PowerScout/Bluetooth/ServiceStore.swift @@ -127,14 +127,16 @@ class ServiceStore: NSObject { } func sendData(_ data:Data) { - if(sessionState != .connected) { - print("ERROR: state is not connected -- can't send data!") - return - } - do { - try MatchTransfer.session.send(data, toPeers: MatchTransfer.session.connectedPeers, with: .reliable) - } catch { - print("ERROR: could not send data!") + if transferType == .multipeerConnectivity { + if(sessionState != .connected) { + print("ERROR: state is not connected -- can't send data!") + return + } + do { + try MatchTransfer.session.send(data, toPeers: MatchTransfer.session.connectedPeers, with: .reliable) + } catch { + print("ERROR: could not send data!") + } } }