[英]Xamarin iOS - How get current bluetooth state?
我在Xamarin iOS应用程序(带有Xamarin Forms)中使用经典蓝牙。 我需要获取当前的蓝牙状态。 仅获得-“开”或“关”,未设置。 我使用以下代码:
public class CbCentralDelegate : CBCentralManagerDelegate
{
public override void UpdatedState(CBCentralManager central)
{
if (central.State == CBCentralManagerState.PoweredOn)
{
System.Console.WriteLine("Powered On");
}
}
}
public class BlManager: IBluetoothHelper
{
private readonly CBCentralManager _bluetoothManager;
public BlManager()
{
try
{
//this i get exception
_bluetoothManager = new CBCentralManager(new CbCentralDelegate(), DispatchQueue.DefaultGlobalQueue,
new CBCentralInitOptions { ShowPowerAlert = true });
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public bool IsConnect()
{
return _bluetoothManager.State == CBCentralManagerState.PoweredOn;
}
}
但是在我的BlManager构造函数中,出现异常:
Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
VM Region Info: 0 is not in any region. Bytes before following region: 4364402688
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT 0000000104238000-0000000105db8000 [ 27.5M] r-x/r-x SM=COW ....app/My.iOS
Triggered by Thread: 0
Application Specific Information:
abort() called
也许我需要我的应用程序的特殊权限? 有什么建议吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.