【问题标题】:How to add key NSBluetoothPeripheralUsageDescription to info.plist in a Windows Visual Studio xamarin.ios app如何在 Windows Visual Studio xamarin.ios 应用程序中将密钥 NSBluetoothPeripheralUsageDescription 添加到 info.plist
【发布时间】:2021-01-05 16:03:57
【问题描述】:
我需要将 BLUETOOTH LOW ENERGY (ble) 添加到我的 xamarin.ios 应用程序中,该应用程序是在与我的 Macbook 配对的 Windows Visual Studio 上构建的。 xamarin.ios 上的 BLE 需要 info.plist 中的 NSBluetoothPeripheralUsageDescription。
但是,我不知道如何在 Visual Studio 中使用 info.plist GUI。
【问题讨论】:
标签:
ios
xamarin.ios
bluetooth-lowenergy
core-bluetooth
info.plist
【解决方案1】:
要添加它,我用记事本(或任何文本编辑器)打开 info.plist 并插入行...
NSBluetoothPeripheralUsageDescription
测试我们的设备是否支持 BLE
...接近尾声。
示例...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>BluetoothTest</string>
<key>CFBundleIdentifier</key>
<string>pl.wojciechkulik.BluetoothTest</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
<string>9.3</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/AppIcon.appiconset</string>
<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>YOUR CUSTOM MESSAGE</string>
<!--Description of the Bluetooth request message (required on iOS 13)-->
<key>NSBluetoothAlwaysUsageDescription</key>
<string>YOUR CUSTOM MESSAGE</string></dict>
</plist>
【解决方案2】:
但是,我不知道如何在 Visual Studio 中使用 info.plist GUI。
有两种方法可以在 Visual Studio 中为info.plist 添加NSBluetoothPeripheralUsageDescription。
一个用XML(Text)Editor
打开
然后在<dict></dict>下面添加如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Allow NSBluetoothPeripheralUsageDescription </string>
</dict>
</plist>
另一种方式是用Generic Plist Editor打开的:
然后可以点击+按钮选择Privacy - Bluetooth Peripheral Usage Description并输入Value。
更多信息可以参考Setting Privacy Keys。