简体   繁体   English

在后台模式下将XMPP连接保持为BLE附件(iOS,Swift)

[英]Hold XMPP connection in background mode as BLE accessory (iOS, Swift)

I'm making simple iOS messenger with XMPPFramework . 我正在使用XMPPFramework制作简单的iOS Messenger。 So the problem is, that if i app goes into background it's disconnects from XMPP server, so the only way to store incoming messages without opening app is Push-notification (add message var into push), which is not so good way. 所以问题是,如果我的应用程序进入后台,它将与XMPP服务器断开连接,因此,无需打开应用程序即可存储传入消息的唯一方法是Push-notification(将消息var添加到push中),这种方法不是很好。 Also, ma app make phone acting as iBeacon to track locations of other near phones. 此外,ma app使电话充当iBeacon来跟踪其他附近电话的位置。 As i know, with such capability app can stay active even in background, but can i also hold's XMPP connection while i'm in background, tracking iBeacons? 据我所知,具有这种功能的应用程序甚至可以在后台保持活动状态,但是当我在后台跟踪iBeacons时,我还可以保持XMPP连接吗? Or Apple finds out and reject such app? 还是苹果发现并拒绝了此类应用?

Thanks for help? 感谢帮助?

It is important to distinguish between an iOS app running in the background and one that has been suspended. 区分在后台运行的iOS应用程序和已暂停的iOS应用程序很重要。

Yes, you can use beacon trasmissions to keep your app alive in the background. 是的,您可以使用信标传输以使应用程序在后台保持活动状态。 When it is alive, you can do networking events in the background including XMPP calls. 活着时,您可以在后台进行网络事件,包括XMPP调用。

There are limits to how long a beacon detection can keep an app alive in the background. 信标检测可以使应用程序在后台存活多长时间是有限制的。

On the receiving side, by ranging and monitoring for beacons at the same time, you can keep it alive for 10 seconds for each new beacon region that appears/disappears, and you can extend this to 180 seconds on request. 在接收端,通过同时测距和监视信标,您可以使每个出现/消失的新信标区域保持活动状态10秒钟,并且可以根据要求将其延长到180秒。 It is possible to game this system by rotating the beacon transmitted every 2 minutes to ensure there is always a new entry/exit event. 可以通过旋转每2分钟发送的信标来确保始终存在新的进入/退出事件,从而对该系统进行游戏。

On the transmitting side, iOS devices can only transmit iBeacon packets when they are in the foreground. 在发送方,iOS设备只能在前台运行iBeacon数据包。 So the best you could do is keep the receiving app alive in the background and communicating with XMPP whenever there has been another app in the foreground within beacon range (~50 meters) within the last 3 minutes. 因此,您最好的办法是让接收应用程序在后台保持活动状态,并在最近3分钟内只要信标范围(约50米)内在前台有另一个应用程序,便与XMPP通信。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM