我可以在后台通过蓝牙发现其他 iOS 设备吗?

发布于 2024-10-02 12:58:18 字数 153 浏览 2 评论 0原文

我希望能够在我的应用程序处于后台时通过蓝牙发现其他 iOS 设备。当我的应用程序不在前台时,是否可以使用 Bonjour 或 Game Kit 来进行此发现?

如果发现兼容设备,是否可以执行此操作并发出通知?

另外,我可以在播放音频时在后台运行并进行此检测吗?

I would like to be able to discover other iOS devices over Bluetooth while my application is in the background. Is it possible to use Bonjour or Game Kit to do this discovery while my application is not in the foreground?

Would it be possible to do this and fire off a notification if a compatible device is discovered?

Also, would I be able to run in the background while playing audio and do this detection?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅窗月明清似水 2024-10-09 12:58:18

当您的申请被暂停时,这是不可能的。来自 iOS 应用程序编程指南

在暂停之前取消任何与 Bonjour 相关的服务。当您
应用程序移至后台,
在暂停之前,应该
从 Bonjour 注销并关闭
与任何关联的侦听套接字
网络服务。一个暂停的
应用程序无法响应传入的
无论如何,服务请求。平仓
这些服务阻止他们
当他们似乎可用时
实际上不是。如果不关闭
自己出 Bonjour 服务,
系统关闭这些服务
当您的应用程序被自动
暂停。

准备好处理基于网络的连接失败
套接字。
系统可能会崩溃
套接字连接,而你的
因任何原因而暂停申请
原因的数量。只要你的
基于套接字的代码是为
其他类型的网络故障,例如
信号或网络丢失
过渡,这不应该导致
任何异常问题。当你的
应用程序恢复,如果遇到
使用套接字时失败,简单地说
重新建立连接。

但是,如果您的应用程序正在传输音频,则有必要维持网络连接,因此您应该能够在后台连续播放音频的应用程序中进行 Bonjour 发现。确保您不会通过循环播放无声音频剪辑来滥用此功能,这样您就可以留在后台,否则您的申请将被拒绝。

This is not possible while your application is suspended. From the iOS Application Programming Guide:

Cancel any Bonjour-related services before being suspended. When your
application moves to the background,
and before it is suspended, it should
unregister from Bonjour and close
listening sockets associated with any
network services. A suspended
application cannot respond to incoming
service requests anyway. Closing out
those services prevents them from
appearing to be available when they
actually are not. If you do not close
out Bonjour services yourself, the
system closes out those services
automatically when your application is
suspended.

Be prepared to handle connection failures in your network-based
sockets.
The system may tear down
socket connections while your
application is suspended for any
number of reasons. As long as your
socket-based code is prepared for
other types of network failures, such
as a lost signal or network
transition, this should not lead to
any unusual problems. When your
application resumes, if it encounters
a failure upon using a socket, simply
reestablish the connection.

However, if your application is streaming audio, it would be necessary for it to maintain network connections, so you should be able to do Bonjour discovery while in the background for an application continuously playing audio. Make sure you don't abuse this by playing a silent audio clip in a loop just so that you can stay in the background, or your application will be rejected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文