我正在为我的项目将工作 Swift 代码移植到 Xamarin。每次我调用此函数时,它都会失败,并且不会显示附件选择器对话框。
EAAccessoryManager.SharedAccessoryManager.ShowBluetoothAccessoryPicker(谓词,完成)
以下是我已经确认的一些事情:
- BT radio 已开启
- Info.plist 具有支持的外部附件协议(protocol)
- 尝试确保在 UI 线程上完成调用
- 尝试直接从按钮点击事件调用
- 相同的基本代码在 Swift/Xcode 中工作正常
- 确保根据本文在构建选项中选择了 ARMv7 和 ARM64:iPad Air - CoreBluetooth[ERROR] Cancelling picker as we couldn't communicate with Bluetooth
赛马林:
EAAccessoryManager.SharedAccessoryManager.ShowBluetoothAccessoryPicker(null, completion: ((Foundation.NSError error) => {
Console.WriteLine("My callback");
if (error != null) {
Console.WriteLine(String.Format("Error code: {0} Desc: {1}", error.Code, error.DebugDescription));
Console.WriteLine("Failed? " + EABluetoothAccessoryPickerError.Failed.ToString());
Console.WriteLine("Failed? " + Convert.ToInt64(EABluetoothAccessoryPickerError.Failed));
}
}));
Xcode/ swift :
EAAccessoryManager.sharedAccessoryManager().showBluetoothAccessoryPickerWithNameFilter(nil) { (error) -> Void in
if error != nil {
NSLog("Error code: \(error!.code) \(error.debugDescription)")
}
}
Xamarin 代码不显示选取器,并且总是会失败。
2016-04-05 19:54:02.136 ASGDemo.iOS[6383:2146384] Connect Clicked
2016-04-05 19:54:06.139 ASGDemo.iOS[6383:2146384] BTM: attaching to BTServer
2016-04-05 19:54:09.157 ASGDemo.iOS[6383:2146384] BTM: session attach called back with BT_SESSION_ATTACHED (fffffed0)
2016-04-05 19:54:09.158 ASGDemo.iOS[6383:2146384] BTM: attemping to re-attach in 1 seconds
2016-04-05 19:54:09.242 ASGDemo.iOS[6383:2146384] My callback
2016-04-05 19:54:09.250 ASGDemo.iOS[6383:2146384] Error code: 3 Desc: Error Domain=EABluetoothAccessoryPickerErrorDomain Code=3 "(null)"
2016-04-05 19:54:09.253 ASGDemo.iOS[6383:2146384] Failed? Failed
2016-04-05 19:54:09.254 ASGDemo.iOS[6383:2146384] Failed? 3
最佳答案
Xamarin 的好心人直接帮助了我,所以我在这里发布了解决方案。他们说这是一个已经修复的错误。该更新应在本月晚些时候通过自动更新发布(如果您启用了自动更新)。
目前,他们提供了一种变通方法,我已经验证该变通方法对我和我的项目同事都有效。以下是解决方法的步骤:
- 清理项目
- 在 iOS-Build 部分下的项目选项中取消选中启用特定于设备的构建。
- 从设备中删除旧应用
- 现在,重建/重新部署,它应该可以工作了。
感谢大家的建议和帮助。另外,感谢 Xamarin 的人员及时做出响应。
关于ios - Xamarin/iOS SharedAccessoryManager.ShowBluetoothAccessoryPicker 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36441071/