I'm developing iOS application which works as BLE central with custom services and characteristics.
And the peripheral device is developed by a certain vendor.
The system needs pairing between central and peripheral to write characteristic value. And now I have a problem regarding the pairing.
If I delete paring information on central(iPhone) side by [Forget This Device] in [Bluetooth] of [Settings],
the paring sequence starts again when my application try to write characteristic value after connection and discover service and characteristic.
(Paring dialogue shows on my application)
The sequence is like below,
1. Complete connection
[_centralMgr centralManager:didConnectPeripheral:]
2. Discover service
[_centralMgr peripheral:didDiscoverServices:]
3. Discover characteristic
[_centralMgr peripheral:didDiscoverCharacteristicsForService:error:]
4. Try to write characteristic value
[_centralMgr peripheral:writeValue:forCharacteristic:tyep:]
5. At this timing, paring dialog is shown and user tap [Paring] button
6. Complete writing of characteristic value without error
[_centralMgr peripheral:didWriteValueForCharacteristic:error:]
But if I delete paring information on peripheral device side (by reset the device), the paring sequence doesn't start when my application try to write characteristic value after connection and discover service and characteristic.
Paring dialogue never shows and the response for write request doesn't return.
The sequence is like below,
1. Complete connectiton
[_centralMgr centralManager:didConnectPeripheral:]
2. Discover service
[_centralMgr peripheral:didDiscoverServices:]
3. Discover characteristic
[_centralMgr peripheral:didDiscoverCharacteristicsForService:error:]
4. Try to write characteristic value
[_centralMgr peripheral:writeValue:forCharacteristic:tyep:]
5. At this timing, paring dialog is never shown
6. Response of writing request(in STEP 4.) doesn't return
The vendor of peripheral device is saying that iPhone doesn't request paring even the peripheral device returns write error.
But my application(at least application layer in iOS) doesn't did receive the delegate API of writing error.
Is there anyone who have a same problem ? I'd appreciate it if you would provide some hint or information.
Add the code of writing characteristic value
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(nonnull CBService *)service error:(nullable NSError *)error
{
NSArray* characteristics = service.characteristics;
for (CBCharacteristic* characteristic in characteristics) {
if (characteristic.properties & CBCharacteristicPropertyWrite) {
if ([[characteristic.UUID UUIDString] isEqualToString:MY_CUSTOM_CHARACTERISTIC]) {
NSData* data = MY_CUSTOM_DATA;
[peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
NSLog(@"writeValue:%@", data);
}
}
}
}
In both case(after deleting pairing info. on central/peripheral side), it discovers completely the same characteristic and write same data.
But only in the latter case(deleted on peripheral side), pairing sequence doesn't start.