Не удалось добавить услугу: ошибка Domain = cberRordomain Code = 8 "Указанный UUID не разрешен для этой операции."
Заинтересованное, когда я переключаюсь на использование 128-битных пользовательских Uuids. /> Тем не менее, после того, как Accu-Chek Meter подключается к iPhone, методы делегатов DidReceiveDead и DidSubScribeTo никогда не запускаются. 16
Характеристика UUID: 2A51 - Свойства: 2
Характеристика UUID: 2A52 - Свойства: 40
Характеристика UUID: 2A08 - Свойства: 2 < /p>
Сервис: Информация об устройстве
Характеристика UUID: 2A23 - Properties: 2
uuid: 2A. /> Характерная uuid: 2a25 - Свойства: 2
Характеристика uuid: 2a26 - Свойства: 2
Характеристика uuid: 2a29 - Свойства: 2
Характеристика uuid: 2a2a - свойства: 2
Характеристические 00000000-0000-1000-1000-00000000000000
Характеристика UUID: 00000000-00000000000000
Характеристика UUID: 00000000-0000-1000-1000-000000000001-Свойства: 40
Характеристика UUID: 00000000-000000-1000-000000002. UUID: 00000000-0000-1000-1000-00000000000010-Свойства: 16
Характеристика UUID: 00000000-0000-1000-1000-000000000011-Свойства: 40
Характеристика UUID: 00000000-00000000001000-00000012-ВВАРИ: 18 < /P> P> PRI-PRITERSIOD: PR> < /P> P> P> PRI-PR /P> P> P> P> PRI-PLARIPERS: PR> < /P> P> PRITER TUMESTEE: PRIERSERISTES: PRIERSERISTES: PR> < /P> P> PREERSERSESE: PR> PRITER. через эту характеристику 00000000-0000-1000-1000-00000000000011 < /p>
Код: Выделить всё
peripheral.writeValue(timeData, for: dateTimeCharacteristic, type: .withResponse)
< /code>
Это то, что я реализовал: < /p>
import CoreBluetooth
class TimeGATTServer: NSObject {
var peripheralManager: CBPeripheralManager!
// Using standard 128-bit UUID formats
let timeServiceUUID = CBUUID(string: "00001805-0000-1000-8000-00805F9B34FB")
let currentTimeCharacteristicUUID = CBUUID(string: "00002A2B-0000-1000-8000-00805F9B34FB")
private var timeService: CBMutableService!
var currentTimeCharacteristic: CBMutableCharacteristic!
// AccuCheck-specific configuration
let deviceName = "AccuCheckTimeServer"
var connectedCentral: CBCentral?
override init() {
super.init()
let options: [String: Any] = [
CBPeripheralManagerOptionShowPowerAlertKey: true,
CBPeripheralManagerOptionRestoreIdentifierKey: "com.clario.accucheckserver",
]
peripheralManager = CBPeripheralManager(delegate: self, queue: nil, options: options)
peripheralManager = CBPeripheralManager(
delegate: self,
queue: nil,
options: options
)
}
// MARK: - Service Setup
func setupService() {
// Remove existing service if any
if let service = timeService {
peripheralManager.remove(service)
}
timeService = CBMutableService(type: timeServiceUUID, primary: true)
currentTimeCharacteristic = CBMutableCharacteristic(
type: currentTimeCharacteristicUUID,
properties: [.read, .indicate, .notify],
value: nil,
permissions: [.readable, .writeable]
)
timeService.characteristics = [currentTimeCharacteristic]
peripheralManager.add(timeService)
}
// MARK: - Advertising
func startAdvertising() {
// Clear any existing advertising
peripheralManager.stopAdvertising()
let advertisementData: [String: Any] = [
CBAdvertisementDataServiceUUIDsKey: [timeServiceUUID],
CBAdvertisementDataLocalNameKey: deviceName,
// Many medical devices need this:
CBAdvertisementDataManufacturerDataKey: Data([0x00, 0x01]) // Fake manufacturer ID
]
peripheralManager.startAdvertising(advertisementData)
}
func stopAdvertising() {
peripheralManager.stopAdvertising()
print("Stopped advertising")
}
}
// MARK: - Peripheral Manager Delegate
extension TimeGATTServer: CBPeripheralManagerDelegate {
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
switch peripheral.state {
case .poweredOn:
print("Bluetooth powered on - setting up service")
setupService()
case .poweredOff:
print("Bluetooth powered off")
stopAdvertising()
default:
print("Bluetooth state changed: \(peripheral.state.rawValue)")
}
}
func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) {
if let error = error {
print("Failed to add service: \(error)")
return
}
print("Service successfully added - starting advertising")
DispatchQueue.global().asyncAfter(deadline: .now() + 1.0) {
self.startAdvertising()
}
}
func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) {
if let error = error {
print("Advertising failed: \(error)")
} else {
print("Now advertising")
}
}
func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveRead request: CBATTRequest) {
print("Read request from \(request.central.identifier.uuidString)")
// Add security check
if request.central.maximumUpdateValueLength == 0 {
print("Security issue - rejecting read")
peripheral.respond(to: request, withResult: .insufficientAuthentication)
return
}
guard request.characteristic.uuid == currentTimeCharacteristicUUID else {
peripheral.respond(to: request, withResult: .requestNotSupported)
return
}
request.value = getCurrentTimeData()
peripheral.respond(to: request, withResult: .success)
}
func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didSubscribeTo characteristic: CBCharacteristic) {
self.connectedCentral = central
// Immediately send current time
let timeData = self.getCurrentTimeData()
peripheral.updateValue(timeData, for: self.currentTimeCharacteristic, onSubscribedCentrals: nil)
}
func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didUnsubscribeFrom characteristic: CBCharacteristic) {
print("Central \(central.identifier.uuidString) disconnected")
connectedCentral = nil
}
func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {
requests.forEach { request in
print("Write request received for \(request.characteristic.uuid)")
peripheral.respond(to: request, withResult: .success)
}
}
}
// MARK: - Data Extension for Debugging
extension Data {
func hexEncodedString() -> String {
return map { String(format: "%02hhX", $0) }.joined(separator: ":")
}
}
< /code>
Мне нужно знать, что я что -то упускаю или просто счетчик не ищет услугу? Он работает на стороне Android с Bluetoothgattservice
Подробнее здесь: https://stackoverflow.com/questions/797 ... ver-on-ios