Skip to content

Commit

Permalink
Fix sendData bug
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pr1sm committed Mar 1, 2018
1 parent 01fbcd0 commit 9cf8815
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 6 additions & 0 deletions PowerScout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
18 changes: 10 additions & 8 deletions PowerScout/Bluetooth/ServiceStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
}
}

Expand Down

0 comments on commit 9cf8815

Please sign in to comment.