- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 Xamarin 和这个 BLE 插件构建一个 iOS 应用程序:
https://github.com/aritchie/bluetoothle
我只是通过 BLE 广播一个 UUID,它可以工作。这是我的代码:
var data = new Plugin.BluetoothLE.Server.AdvertisementData
{
LocalName = "MyServer",
};
data.ServiceUuids.Add(new Guid("MY_UUID_HERE"));
await this.server.Start(data);
唯一的问题是,一旦我将应用程序置于后台,它就会停止广播。并在我再次打开应用程序时再次恢复。
如何让它在后台继续播放?我在这里阅读了文档:
它说我必须使用 CBCentralManager
类来获得保存和恢复功能(这样我就可以一直广播 UUID),但我很难翻译这对 Xamarin/C#。
编辑
进一步研究后,我了解到我需要创建一个 CBCentralManager
实例并在委托(delegate)中实现 WillRestoreState
。我在 AppDelegate
中这样做了:
[Register("AppDelegate")]
public class AppDelegate : MvxApplicationDelegate, ICBCentralManagerDelegate
{
private IGattServer server = CrossBleAdapter.Current.CreateGattServer();
private CBCentralManager cbCentralManager;
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
// irrelevant code...
this.Ble();
return true;
}
private async Task Ble()
{
try
{
await Task.Delay(5000); // wait for it to finish initializing so I can access BLE (it crashes otherwise)
var options = new CBCentralInitOptions();
options.RestoreIdentifier = "myRestoreIndentifier";
this.cbCentralManager = new CBCentralManager(this,null,options);
var data = new Plugin.BluetoothLE.Server.AdvertisementData
{
LocalName = "MyServer",
};
data.ServiceUuids.Add(new Guid("MY_UUID_HERE"));
await this.server.Start(data);
}
catch (Exception e)
{
}
}
public void UpdatedState(CBCentralManager central)
{
//throw new NotImplementedException();
}
[Export("centralManager:willRestoreState:")]
public void WillRestoreState(CBCentralManager central, NSDictionary dict)
{
//never gets called
}
但这对我来说并没有什么不同。而且 WillRestoreState
方法永远不会被调用...我不介意在这一点上使用不同的插件/库...
编辑 2
我刚刚意识到该应用程序在后台时仍在广播,我只是再也看不到服务 UUID(在我正在测试的信标的门户网站中),我只看到手机的标识符。
最佳答案
经过大量研究,我发现这只是一个 iOS 限制 - 当您的应用程序处于后台时,您不能广播 BLE 服务的 UUID。后台工作在 iOS 中非常受限。
编辑以包含 Paulw11 评论(这是真的):您可以宣传一项服务,但其宣传方式只有专门扫描该服务 UUID 的另一台 iOS 设备才能看到。
关于ios - 在应用程序处于后台时使用蓝牙 LE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44662206/
当我向我的安装程序添加依赖项时,我总是留下文件的硬编码路径。 根据 this blog ,解决此问题的唯一方法是使用 ISProjectFolder 变量手动更改 ISL 文件中的硬编码路径。这没有任
我想开发像蓝牙 LE 外围设备这样的应用程序,它停止在与蓝牙 LE 中央设备连接时做广告,并限制与多个蓝牙 LE 中央设备连接的蓝牙 LE 外围设备。 一个蓝牙 LE 外围设备一次只能与一个蓝牙 LE
示例代码: # Step 1 $start = get-date for($i=1; $i -le 1000000; $i++){} $end = get-date ($end-$start).Tot
在Basic customisation ,python 文档说明了比较方法: [no swapped-argument versions of these methods]; rather, __l
蓝牙双模设备是否可以在与 BT LE 设备配对的同时被经典蓝牙发现?如果设备不能同时运行这两种模式也没关系,但我真的应该在这些模式之间切换芯片吗?我只是在 BT 4 Core 规范中找不到答案 最佳答
我正在尝试使用 fscanf 从输入文件中读取 3 个 double 值,但在尝试这样做时遇到了段错误。我的代码如下: FILE * infile = fopen(argv[1], "r");
我的域指向另一个网站,我想为其安装 LE 证书,这可能吗,或者我的域应该链接到服务器? 最佳答案 letsencrypt 不允许安装非 NS 指向,因为它检查反向验证,所以它会失败 关于wordpre
在我的 Android(API 版本 21 及更高版本)Bluetooth LE 应用程序中,该应用程序首先使用 BluetoothLeScanner 和 ScanCallback 对象扫描外围设备。
我正在使用 Xamarin 和这个 BLE 插件构建一个 iOS 应用程序: https://github.com/aritchie/bluetoothle 我只是通过 BLE 广播一个 UUID,它
我可以在点击时同时扫描蓝牙和蓝牙 LE 设备吗? 最佳答案 答案是否定的。 原文来自: http://developer.android.com/guide/topics/connectivity/b
关于 Dennis Mathews answer,您如何在 iOS 上指定经典蓝牙而不是 LE?有没有和Core Bluetooth Framework?不同的api 最佳答案 Joels 有一种在
我有一个使用 BLE 的应用程序。在某些情况下,例如当安装在 iPhone 6 上时,应用程序正在运行并且不请求使用 BLE 的许可。 在其他情况下,比如我的 iPad Air,应用程序开始运行,并且
我尝试使用 Bluetooth LE 检测设备,按照 Xamarin 库中的说明执行此操作,但设备发现 0 包括 android 中的必要声明。将扫描时间增加到 30 秒,但没有任何效果。支持蓝牙,版
配对“普通”蓝牙设备和配对蓝牙 LE 设备之间是否存在任何(大)技术差异? 我找到了很多关于蓝牙 LE 配对的信息,但没有正常的?例如 Info 1 . 那么普通蓝牙的这个信息也正确吗? 最佳答案 如
我尝试使用下面的代码将发现的设备的UUID存储到Array,然后在该阵列中选择UUID进行连接,但无法运行。 - (void)centralManager:(CBCentralManager *)ce
我正在研究一个通过蓝牙 LE 发送数据的 Android 应用程序。这里有两种方法让我感到困惑。有人可以解释一下这两种方法及其相互关系吗: private String localmessage =
我在使用 BluetoothLeScanner 的 startScan 方法时遇到了问题,找到了一个 BLE 设备,但是当我关闭 BLE 设备时,我的手机仍然显示此设备已打开!! 我尝试过使用: pr
我使用 StartLeScan 已经有一段时间了,扫描后返回的设备的名称从未被填充。我永远无法弄清楚为什么,我只是找回了 mac 地址。今天我从 OS BT 设置页面运行扫描,它只显示 MAC 地址,
在实现大量使用 Service 的 Android 应用程序方面,我不是很有经验,而且我在 SO 或 github 上找不到任何好的建议或示例来帮助我(或者只是谷歌搜索)所以我决定问我自己的问题。 当
开发用于蓝牙技术的移动应用程序能否用于蓝牙 LE 技术? 或者开发人员是否需要修改代码来处理蓝牙 LE(智能)信号、输入、输出等? 编辑 问这个问题的时候我想知道 如果我写一段代码,我可以在 BLE
我是一名优秀的程序员,十分优秀!