iOS 可以同时在同一个应用程序上做中央和外围工作吗? [英] Can iOS do central and peripheral work on same app at same time?

查看:21
本文介绍了iOS 可以同时在同一个应用程序上做中央和外围工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS(iPhone 或 iPad)应用能否同时拥有 Core Bluetooth (BTLE) 中央管理器和外设管理器对象?

它们是否可以异步运行,或者主应用线程是否需要让它们共享(来回切换).

共享概念算法将是:禁用外围管理器,启用中央管理器并执行中央功能,接着,禁用中央管理,启用外围管理,做外围功能(即发送自动通知,等待和响应远程特征命令),重复...

背景血腥细节:我们有一个本地系统,其中包含多个 iOS 设备和多个需要通过 BTLE 相互通信的非 iOS 设备.非iOS设备均使用Broadcom BCM20732蓝牙LE芯片.但是硬件还没有准备好,所以我使用 iOS 设备来模拟非 iOS,这需要同时具有中央和外围功能,即.1.作为中心定期询问系统中的多个其他非iOS设备.2. 作为外围设备响应来自 iOS 用户界面设备的数据请求.

解决方案

我搞定了.我刚开始使用 Apple 的BTLE 中央外设传输",然后首先删除它的 -35 db 错误(搜索-35"然后删除 if(){ return }),然后我将两个 central.m 结合起来和peripheral.m 到单个 UIViewController .m 文件中,添加了一个 UISwitch 以选择两个服务 UUID 之一,并修改了外设发送器以自动增加文本字段(在将其初始化为 ASCII '0' 后).

我有两台 iPad mini,每台都向另一侧发送递增的数字.它最多传输了 900 多次,然后就挂了.但是我看到 Apple 的BTLE c p transfer"总是在几分钟后挂起,需要重新启动 iPad 才能继续.我在 iPad 和循环电源上结束应用程序,重新启动应用程序,它们增加了 1600 增量,然后挂起.

为了解决挂起问题,我将按照 Abo 的建议添加资源控制,以防止中央和外围管理器同时连接.

Can iOS (iPhone or iPad) app have Core Bluetooth (BTLE) central manger and peripheral manager objects at same time?

Can they operate asynchronously, or does main app thread need to make them share (switch back and forth).

Sharing conceptual algorithm would be: disable peripheral manager, enable central manager and do central functions, and then, disable central mgr, enable peripheral mgr, and do peripheral functions (that is, send automatic nofications, and wait for and respond to remote characteristic commands), repeat...

BACKGROUND GORY DETAILS: We have a local system with multiple iOS devices and multiple non-iOS devices that need to inter-communicate by BTLE. The non-iOS devices all use Broadcom BCM20732 Bluetooth LE chip. But hardware is not ready yet, so I'm using iOS devices to emulate the non-iOS, which requires simultaneous central AND peripheral functionality, ie. 1. act as central to periodically interrogate multiple other non-iOS devices in system. 2. act as peripheral to respond to requests for data from iOS user interface devices.

解决方案

I got it working. I just started with the Apple "BTLE central peripheral transfer", then first delted the -35 db bug that it has (search for "-35" then delete the if(){ return }), then I combined both the central.m and the peripheral.m into a single UIViewController .m file, added a UISwitch to select one of two service UUID's, and modified the peripheral sender to automatically increment the text field (after init'ing it to ASCII '0').

I had two iPad mini's continuously each sending the incrementing number to the other side. It got up to over 900 transfers and then hung. But I've seen the Apple "BTLE c p transfer" always hang after a few minutes, requiring iPad restart to continue. I ended app at both iPad's and cycled power, re-started app, and they got up to 1600 increments, and then hung.

To solve the hang, I'll add resource control to prevent central and peripheral managers from connecting at same time, as per Abo's recommendation.

这篇关于iOS 可以同时在同一个应用程序上做中央和外围工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆