iOS和Android的蓝牙扫描仪(Xamarin形式)

问题描述 投票:0回答:1

我们正在实现可在iOS和Android上使用的Xamarin Forms App。应用必须具有使用相机和蓝牙设备的条形码扫描功能。尽管完成了摄像头部分,但我们仍在寻找蓝牙设备集成。我们尝试了Socket Scanner,它可以在iOS上完美运行,但不能在Android上运行。还有其他可以在iOS和Android上使用的蓝牙扫描仪吗?如果没有,我们应该分别为iOS和Android实现蓝牙。请提供SDK和硬件的链接(如果有)。

谢谢。

xamarin.forms xamarin.android bluetooth xamarin.ios bluetooth-lowenergy
1个回答
0
投票

对于Xamarin中的蓝牙,您可以使用Nuget的插件Plugin.BLE

首先,请不要忘记将权限添加到特定平台

在Android中

将以下行添加到AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

在iOS中

将以下行添加到info.plist

<key>UIBackgroundModes</key>
<array>
    <!--for connecting to devices (client)-->
    <string>bluetooth-central</string>

    <!--for server configurations if needed-->
    <string>bluetooth-peripheral</string>
</array>

<!--Description of the Bluetooth request message (required on iOS 10, deprecated)-->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App want to access the bluetooth</string>

<!--Description of the Bluetooth request message (required on iOS 13)-->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>App want to access the bluetooth</string>

用法

var ble = CrossBluetoothLE.Current;
var state = ble.State;
var adapter = CrossBluetoothLE.Current.Adapter;

有关更多详细信息和用法,您可以检查https://github.com/xabre/xamarin-bluetooth-le

© www.soinside.com 2019 - 2024. All rights reserved.