Skip to content

Commit

Permalink
Fixed GATTServer notifications
Browse files Browse the repository at this point in the history
Don’t call delegate closure for local writes, only for incoming GATT
write requests.
  • Loading branch information
colemancda committed Jan 18, 2019
1 parent ec06e90 commit ab33985
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/GATTServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public final class GATTServer {

database.write(value, forAttribute: handle)

didWriteAttribute(handle)
didWriteAttribute(handle, isLocalWrite: true)
}

/// Update the value of a characteristic attribute.
Expand Down Expand Up @@ -271,7 +271,7 @@ public final class GATTServer {
didWriteAttribute(handle)
}

private func didWriteAttribute(_ attributeHandle: UInt16) {
private func didWriteAttribute(_ attributeHandle: UInt16, isLocalWrite: Bool = false) {

let (group, attribute) = database.attributeGroup(for: attributeHandle)
assert(attribute.handle == attributeHandle)
Expand All @@ -281,7 +281,9 @@ public final class GATTServer {
else { return }

// inform delegate
didWrite?(attribute.uuid, attribute.handle, attribute.value)
if isLocalWrite == false {
didWrite?(attribute.uuid, attribute.handle, attribute.value)
}

// Client configuration
if let clientConfigurationDescriptor = characteristic.descriptors.first(where: { $0.uuid == .clientCharacteristicConfiguration }) {
Expand Down

0 comments on commit ab33985

Please sign in to comment.