我们正在实现在iOS和安卓上工作的Xamarin Forms应用程序。应用程序需要有条形码扫描功能,使用相机和蓝牙设备。虽然摄像头部分已经完成,我们仍然在寻找蓝牙设备的集成。我们尝试了Socket,它在iOS上工作得很好,但在安卓系统上就不行了。还有其他蓝牙扫描仪可以同时工作在iOS和安卓上吗?如果不是,我们应该分别为iOS和安卓实现蓝牙。如果可用,请提供SDK和硬件的链接。
谢谢。
发布于 2020-01-31 05:13:53
对于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
https://stackoverflow.com/questions/59990928
复制相似问题