启动服务器时ACR反应式BluetoothLE插件无效状态 [英] ACR Reactive BluetoothLE Plugin Invalid State when starting server

查看:118
本文介绍了启动服务器时ACR反应式BluetoothLE插件无效状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xamarin和MvvmCross跨设备使用蓝牙LE来构建iOS应用程序.我正在尝试使用此插件:

I am building an iOS app with Xamarin and MvvmCross the required the use of Bluetooth LE. I am trying to use this plugin:

https://github.com/aritchie/bluetoothle

这是我的代码:

var server = CrossBleAdapter.Current.CreateGattServer();
await server.Start(new AdvertisementData()); // throws exception

尝试启动服务器时会引发异常:

It throws an exception when trying to start the server:

{System.ArgumentException:无效状态-在以下位置未知 Plugin.BluetoothLE.Server.GattServer.Start (Plugin.BluetoothLE.Server.AdvertisementData adData)[0x0005f]在 < 4281c4bd57f24525b20baae1afdf610b>:0

{System.ArgumentException: Invalid State - Unknown at Plugin.BluetoothLE.Server.GattServer.Start (Plugin.BluetoothLE.Server.AdvertisementData adData) [0x0005f] in <4281c4bd57f24525b20baae1afdf610b>:0

显然,此插件易于使用,因此我必须缺少明显的东西吗?

Apparently this plugin is easy to use so I must be missing something obvious?

推荐答案

我找到了解决方案.我没有将代码放置在我的Core项目中,而是将其放置在iOS项目本身的ViewDidAppear函数中,并在UIViewController类中放置了一个全局变量:

I found a solution. Instead of placing the code in my Core project, I placed it inside the iOS project itself, in a ViewDidAppear function, and placed a global variable in my UIViewController class:

private IGattServer server = CrossBleAdapter.Current.CreateGattServer();

我认为您需要使用适当的线程或在适当的时间(在其他初始化之后)访问适配器,因此为什么以前它会崩溃.我找不到在Core项目中放置此代码的合适位置,因此我不确定是否必须在每个平台中放置此代码.无论如何,这是解决此问题的任何人的解决方案.

I think you need to access the adapter with the appropriate thread, or at the appropriate time (after other initialization), hence why it was crashing before. I couldn't find an appropriate place to put this in my Core project, so I'm not sure if I have to put this code in each platform. Anyhow here's a solution for anyone else with this problem.

这篇关于启动服务器时ACR反应式BluetoothLE插件无效状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆