munim-bluetooth 0.3.17 → 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -196,15 +196,32 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
196
196
  }
197
197
  }
198
198
 
199
- var value: Data?
200
- if let valueString = characteristic.value {
201
- value = hexStringToData(valueString)
202
- if !properties.contains(.read) {
203
- properties.insert(.read)
199
+ // Important: In CoreBluetooth, if you provide a 'value' parameter,
200
+ // the characteristic becomes cached and read-only.
201
+ // For writable characteristics, the value MUST be nil.
202
+ var value: Data? = nil
203
+ let hasWriteProperty = properties.contains(.write) || properties.contains(.writeWithoutResponse)
204
+
205
+ if !hasWriteProperty {
206
+ // Only set a static value for read-only characteristics
207
+ if let valueString = characteristic.value {
208
+ value = hexStringToData(valueString)
204
209
  }
205
210
  }
206
211
 
207
- let permissions: CBAttributePermissions = value != nil ? .readable : [.readable, .writeable]
212
+ // Always ensure read is present if we have a value
213
+ if value != nil && !properties.contains(.read) {
214
+ properties.insert(.read)
215
+ }
216
+
217
+ // Set permissions based on properties
218
+ var permissions: CBAttributePermissions = []
219
+ if properties.contains(.read) {
220
+ permissions.insert(.readable)
221
+ }
222
+ if hasWriteProperty {
223
+ permissions.insert(.writeable)
224
+ }
208
225
 
209
226
  let mutableChar = CBMutableCharacteristic(
210
227
  type: charUUID,
@@ -214,7 +231,8 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
214
231
  )
215
232
 
216
233
  characteristics.append(mutableChar)
217
- NSLog("[MunimBluetooth] Characteristic added: %@ with properties: %lu", characteristic.uuid, properties.rawValue)
234
+ NSLog("[MunimBluetooth] Characteristic added: %@ with properties: %lu, hasValue: %@",
235
+ characteristic.uuid, properties.rawValue, value != nil ? "YES" : "NO")
218
236
  }
219
237
 
220
238
  mutableService.characteristics = characteristics
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "munim-bluetooth",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
4
4
  "description": "A comprehensive React Native library for all your Bluetooth Low Energy (BLE) needs, supporting both peripheral and central roles with Expo support",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",