munim-bluetooth 0.3.17 → 0.3.19
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.
- package/ios/HybridMunimBluetooth.swift +48 -17
- package/package.json +1 -1
|
@@ -95,34 +95,47 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
95
95
|
|
|
96
96
|
var advertisingData: [String: Any] = [:]
|
|
97
97
|
|
|
98
|
-
// Service UUIDs
|
|
98
|
+
// Service UUIDs - ALLOWED
|
|
99
99
|
if !options.serviceUUIDs.isEmpty {
|
|
100
100
|
let uuids = options.serviceUUIDs.compactMap { CBUUID(string: $0) }
|
|
101
101
|
advertisingData[CBAdvertisementDataServiceUUIDsKey] = uuids
|
|
102
102
|
NSLog("[MunimBluetooth] Advertising service UUIDs: %@", options.serviceUUIDs)
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
// Local name
|
|
105
|
+
// Local name - ALLOWED
|
|
106
106
|
if let localName = options.localName {
|
|
107
107
|
advertisingData[CBAdvertisementDataLocalNameKey] = localName
|
|
108
108
|
NSLog("[MunimBluetooth] Advertising local name: %@", localName)
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
// Manufacturer data
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
NSLog("[MunimBluetooth]
|
|
111
|
+
// Manufacturer data - NOT ALLOWED by iOS for peripheral advertising
|
|
112
|
+
// This can only be included when you're a central scanning for peripherals
|
|
113
|
+
if options.manufacturerData != nil {
|
|
114
|
+
NSLog("[MunimBluetooth] ⚠️ WARNING: Manufacturer data cannot be advertised on iOS")
|
|
115
|
+
NSLog("[MunimBluetooth] iOS only allows localName and serviceUUIDs in peripheral advertisements")
|
|
116
|
+
// Don't add it to advertisingData - it will cause a warning/error
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
// Advertising data
|
|
119
|
+
// Advertising data types - Most are NOT ALLOWED
|
|
119
120
|
if let advertisingDataTypes = options.advertisingData {
|
|
120
|
-
|
|
121
|
+
// Only process allowed fields
|
|
122
|
+
if let completeLocalName = advertisingDataTypes.completeLocalName {
|
|
123
|
+
advertisingData[CBAdvertisementDataLocalNameKey] = completeLocalName
|
|
124
|
+
NSLog("[MunimBluetooth] Using complete local name from advertising data: %@", completeLocalName)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Warn about unsupported fields
|
|
128
|
+
if advertisingDataTypes.txPowerLevel != nil {
|
|
129
|
+
NSLog("[MunimBluetooth] ⚠️ WARNING: txPowerLevel cannot be set in peripheral advertisements on iOS")
|
|
130
|
+
}
|
|
131
|
+
if advertisingDataTypes.flags != nil {
|
|
132
|
+
NSLog("[MunimBluetooth] ⚠️ WARNING: flags cannot be set in peripheral advertisements on iOS")
|
|
133
|
+
}
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
currentAdvertisingData = options.advertisingData
|
|
124
137
|
|
|
125
|
-
NSLog("[MunimBluetooth] Starting advertising with data: %@", advertisingData)
|
|
138
|
+
NSLog("[MunimBluetooth] Starting advertising with allowed data: %@", advertisingData)
|
|
126
139
|
peripheralManager.startAdvertising(advertisingData)
|
|
127
140
|
}
|
|
128
141
|
|
|
@@ -196,15 +209,32 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
196
209
|
}
|
|
197
210
|
}
|
|
198
211
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
212
|
+
// Important: In CoreBluetooth, if you provide a 'value' parameter,
|
|
213
|
+
// the characteristic becomes cached and read-only.
|
|
214
|
+
// For writable characteristics, the value MUST be nil.
|
|
215
|
+
var value: Data? = nil
|
|
216
|
+
let hasWriteProperty = properties.contains(.write) || properties.contains(.writeWithoutResponse)
|
|
217
|
+
|
|
218
|
+
if !hasWriteProperty {
|
|
219
|
+
// Only set a static value for read-only characteristics
|
|
220
|
+
if let valueString = characteristic.value {
|
|
221
|
+
value = hexStringToData(valueString)
|
|
204
222
|
}
|
|
205
223
|
}
|
|
206
224
|
|
|
207
|
-
|
|
225
|
+
// Always ensure read is present if we have a value
|
|
226
|
+
if value != nil && !properties.contains(.read) {
|
|
227
|
+
properties.insert(.read)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Set permissions based on properties
|
|
231
|
+
var permissions: CBAttributePermissions = []
|
|
232
|
+
if properties.contains(.read) {
|
|
233
|
+
permissions.insert(.readable)
|
|
234
|
+
}
|
|
235
|
+
if hasWriteProperty {
|
|
236
|
+
permissions.insert(.writeable)
|
|
237
|
+
}
|
|
208
238
|
|
|
209
239
|
let mutableChar = CBMutableCharacteristic(
|
|
210
240
|
type: charUUID,
|
|
@@ -214,7 +244,8 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
214
244
|
)
|
|
215
245
|
|
|
216
246
|
characteristics.append(mutableChar)
|
|
217
|
-
NSLog("[MunimBluetooth] Characteristic added: %@ with properties: %lu
|
|
247
|
+
NSLog("[MunimBluetooth] Characteristic added: %@ with properties: %lu, hasValue: %@",
|
|
248
|
+
characteristic.uuid, properties.rawValue, value != nil ? "YES" : "NO")
|
|
218
249
|
}
|
|
219
250
|
|
|
220
251
|
mutableService.characteristics = characteristics
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "munim-bluetooth",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.19",
|
|
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",
|