简体   繁体   English

为什么有时我需要重新启动iOS蓝牙(使用系统按钮)才能使我的中央管理器能够成功连接?

[英]Why, sometimes, do I need to restart the iOS Bluetooth (using the system button) to make my central manager able to connect successfully?

I'm developing an application on iOS and OS X Yosemite which is using CoreBluetooth on iOS and IOBluetooth on Mac. 我正在iOS和OS X Yosemite上开发一个应用程序,该应用程序在iOS上使用CoreBluetooth,在Mac上使用IOBluetooth。 The iOS app plays the "central" role while the Mac app is playing the "peripheral" role. iOS应用程序扮演“中心”角色,而Mac应用程序扮演“外围”角色。

Basically, the iOS app (the central) starts a scan to find peripherals and when it finds a Mac advertising peripherals data, the central connects to it and can discover its services and characteristics. 基本上,iOS应用(中央)开始扫描以查找外围设备,当找到Mac广告外围设备数据时,中央将连接到它并发现其服务和特征。

My problem is that sometimes, I don't know why, the iOS app starts a scan to find a Mac advertising and when it finds it (this step work all the time), it tries to connect to it but never succeed. 我的问题是,有时我不知道为什么,iOS应用程序开始扫描以查找Mac广告,当它找到它时(此步骤一直有效),它尝试连接到该广告,但从未成功。

To make it able to connect successfully to the peripheral again, I need to turn off and then turn on the Bluetooth from the iOS button. 为了使其能够再次成功连接到外围设备,我需要先关闭然后再通过iOS按钮打开蓝牙。

Another strange thing is : imagine the central is in the same situation (trying to connect with no success). 另一个奇怪的事情是:想象中心处于相同的情况(尝试连接失败)。 On OS X if I click on the Network icon (with the Wifi symbol) in the system status bar, then it will display the list of all available Wifi networks, and when it adds to the list my iPhone as a "Personal hotspot", at this time the central (which is on the iPhone) manages to connect to the peripheral (the Mac). 在OS X上,如果我单击系统状态栏中的“网络”图标(带有Wifi符号),则它将显示所有可用Wifi网络的列表,当它作为“个人热点”添加到我的iPhone中时,此时,中央设备(在iPhone上)设法连接到外围设备(Mac)。

带有可用iPhone热点的Wifi菜单

With this problem, the app usage is a lot compromised because randomly the iPhone will not be able to connect to the Mac. 有了这个问题,由于iPhone随机将无法连接到Mac,因此应用程序的使用受到很大影响。

I spent a lot of days on the internet (Google, Stackoverflow, ...) to find similar cases. 我花了很多天在互联网(Google,Stackoverflow等)上找到类似的案例。 I read a lot of articles and tried a lot of things like stopping the scan and starting it again if the connection didn't succeed after 10 seconds for example. 我阅读了很多文章,并尝试了很多操作,例如停止扫描并在10秒钟后如果连接未成功就重新启动扫描。

Don't hesitate to tell me if my question is not clear. 如果我的问题不清楚,请不要犹豫告诉我。 I will update it if needed. 如果需要,我将对其进行更新。

Thanks a lot in advance for your help. 在此先感谢您的帮助。 I really need to find a way to fix this. 我真的需要找到一种方法来解决此问题。

I don't have an answer (and not enough rep to comment) but I have been experiencing a very similar problem for months now. 我没有答案(也没有足够的代表发表评论),但是几个月来我一直遇到一个非常相似的问题。 My iOS app which is playing the central role sometimes fails to discover services on the peripheral (linux) which can only be fixed by power cycling the bluetooth radio on my iOS device via settings/bluetooth. 扮演中心角色的我的iOS应用有时有时无法发现外围设备(linux)上的服务,而这些服务只能通过重新启动我的iOS设备上的蓝牙无线电通过设置/蓝牙来修复。 After bouncing the bluetooth radio, peripheral discovery appears to works perfectly. 弹起蓝牙无线电后,外设发现似乎运行良好。

I've found two reproducible cases: (1) If on my peripheral I completely swap out the service being advertised (ie change the service UUID and all characteristics) then the iOS peripheral will detect the peripheral with this new service during the scan, but service discovery fails. 我发现了两种可重现的情况:(1)如果在我的外围设备上我完全交换了要宣传的服务(即更改服务UUID和所有特征),则iOS外围设备将在扫描期间检测到具有此新服务的外围设备,但是服务发现失败。 I find that peripheral:didDiscoverServices gets invoked, but the list of services is empty for this peripheral. 我发现外围设备:didDiscoverServices被调用,但是此外围设备的服务列表为空。 (2) If on my peripheral, I modify the list of characteristics in any way (add a new one, remove one) the iOS app does not notice this change at all. (2)如果在我的外围设备上,我以任何方式修改了特性列表(添加一个新特性,然后删除一个特性),iOS应用程序根本不会注意到此更改。 During characteristics discovery, the same list of characteristics (prior to modification) is presented. 在特征发现期间,将显示相同的特征列表(在修改之前)。 Again, power-cycling the bluetooth radio on the iOS device appears to be the only thing that fixes this. 同样,重启iOS设备上的蓝牙无线电似乎是解决此问题的唯一方法。

It appears as though iOS is caching BTLE peripheral services and characteristics upon discovering a new peripheral and the only way to flush this cache is to power cycle the bluetooth radio. 在发现新的外围设备后,iOS似乎正在缓存BTLE外围设备服务和特征,并且刷新此缓存的唯一方法是重启蓝牙无线电。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS蓝牙中央管理器 - iOS Bluetooth Central Manager iOS-按下按钮时,如何让系统远程呼叫服务器? - iOS - when a button is pressed, how do I get the system to make a remote call to my server? 如何使用蓝牙4.0(BLE)如何使A2DP蓝牙配置文件工作? 我需要AptX编解码器吗? - How are you able to get an A2DP bluetooth profile to work using bluetooth 4.0 (BLE)? Do I need an AptX codec? iOS:如何在使用Grand Central Dispatch(GCD)时同步我的managedObjectContext? - iOS: How do I synchronize my managedObjectContext when using Grand Central Dispatch (GCD)? iOS:为什么我的视图需要x值约束? - iOS: Why do I need an x value Constraint for my View? 将 iOS 更新到 15.1 后,我无法连接到蓝牙 - I am unable to connect to bluetooth after updating my iOS to 15.1 为什么我无法按下 iOS 上的按钮? - Why am I not able to press the button on iOS? 使用Visual Studio 2017无法连接Xamarin.IOS中的MAC系统 - Not Able to Connect with MAC System in Xamarin.IOS using VisualStudio 2017 Xamarin.ios Core蓝牙中央管理器:检索带有标识符的已知外围设备 - Xamarin.ios Core Bluetooth Central Manager : retrieve known peripherals with identifiers Swift:为Bluetooth Central Manager选择队列 - Swift: Choose queue for Bluetooth Central manager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM