【发布时间】:2020-01-31 20:33:54
【问题描述】:
我在我的应用程序中添加了 Siri 快捷方式并使用语音命令
我在调试器中遇到的错误是:
[CoreBluetooth] API MISUSE:只能在 开机状态
我在这里查看了大量重复的问题,一致认为CBCentralManager 需要是一个类级别的变量,我有。
我仍然无法让 UpdatedState 委托方法在 Siri 语音命令或新的 iOS 13 快捷方式应用程序的上下文中执行多次。这意味着我的应用程序无法执行连续功能。
请记住,它运行一次,然后如果我再次打开应用程序或重新运行调试会话,它将再次运行一次,但随后停止运行,因为从未调用过 UpdatedState
这里会发生什么?我怎样才能让我的CBCentralManager 保持活力?
连接管理器:
public class BleConnectionManagerIos : CBCentralManagerDelegate
{
CBCentralManager centralManager;
public BleConnectionManagerIos()
{
var dict = NSDictionary.FromObjectsAndKeys(new object[] { false },
new object[] { CBCentralManager.OptionShowPowerAlertKey });
this.centralManager = new CBCentralManager(this, null, dict);
}
//THIS METHOD IS ONLY EXECUTED ONE TIME ONLY
public override void UpdatedState(CBCentralManager central)
{
if (central.State == CBCentralManagerState.PoweredOn)
{
//powered on
}
else
{
//not powered on
}
}
}
Siri 快捷方式 Intent 处理程序:
[Register("IntentHandler")]
public class IntentHandler : INExtension
{
public override NSObject GetHandler(INIntent intent)
{
if (intent is MyIntent)
{
return new MyIntentHandler();
}
throw new Exception("Unhandled intent type: ${intent}");
}
protected IntentHandler(IntPtr handle) : base(handle) { }
}
意图处理程序:
public class MyIntentHandler : MyIntentHandling
{
AppExtensionViewModel viewModel;
AppExtensionViewModel ViewModel
{
get
{
if (this.viewModel == null)
{
this.viewModel = new AppExtensionViewModel();
}
return this.viewModel;
}
}
public override void HandleTheIntent(MyIntent intent, Action<MyIntentResponse> completion)
{
this.ViewModel.DoSomething();
}
视图模型:
public class AppExtensionViewModel
{
IBleConnectionManager BleConnectionManager;
public AppExtensionViewModel()
{
this.BleConnectionManager = new BleConnectionManagerIos();
}
}
【问题讨论】:
-
Allan Ritchie,Backgrounding 大师创建了 Shiny 库 github.com/shinyorg/shiny/blob/… 尝试通过 twitter 或其他方式联系他
-
我猜你已经在 info.plist 下添加了蓝牙背景模式
标签: ios xamarin core-bluetooth ios13 sirishortcuts