I created an app where I am able to connect to BLE device and fetch the GATT services and characteristics. But after I write something in GATT characteristics I get pairing request dialog in iOS and the characteristics value becomes null after I accept the pairing request. I don't know why this pairing request is coming only when I'm writing in my GATT characteristics. And BLE doesn't ask for pairing in iOS as per my research. Even though the pairing request dialog is coming I need the pairing request to come after connection or before connection not after write operation. This is the image of the pairing request I'm receiving.
This is my code where I'm connecting and writing to GATT server
private async Task<string> ProcessDeviceInformationService(IService deviceInfoService)
{
try
{
await adapter.ConnectToDeviceAsync(device);
var sb = new StringBuilder("Getting information from Device Information service: \n");
var characteristics = await deviceInfoService.GetCharacteristicsAsync();
var characteristic = await deviceInfoService.GetCharacteristicAsync(Guid.Parse("00002A39-0000-1000-8000-00805F9B34FB"));
try
{
if (characteristic != null)
{
var sbnew = new StringBuilder("BLE Characteristics\n");
byte[] senddata = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(SendMessageLabel.Text) ? "Judson was here" : SendMessageLabel.Text);
await Task.Delay(300);
var newbytes = await characteristic.WriteAsync(senddata);
var bytes = await characteristic.ReadAsync();
var str = Encoding.UTF8.GetString(bytes);
sbnew.AppendLine($"Characteristics found on this device: {string.Join(", ", str.ToString())}");
CharactericsLabel.Text = sbnew.ToString();
}
}
catch (Exception ex)
{
return ex.Message;
}
return CharactericsLabel.Text;
}
catch (Exception ex)
{
return ex.ToString();
}
}
My characteristic value becomes null just after WriteAsync method. I have no clue how to fix this any suggestions?