是否可以在后台实现不间断的 API 端点 ping? [英] Is it possible to implement nonstop API endpoint pinging in background?

查看:87
本文介绍了是否可以在后台实现不间断的 API 端点 ping?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的团队决定在后台实施不间断 API 端点 ping,在收到所需的响应后,应用应显示带有来自响应的消息的通知.我建议通过第三方服务(如 Firebase 或 OneSignal)使用通知,但目前我们更愿意使用不间断 API 端点 ping.

Our team decided to implement non stop API endpoint pinging in background and after receiving required response, app should display a notification with message from response. I suggested using notifications via third party service, like Firebase or OneSignal, but currently we would like to rather use non stop API endpoint pinging.

我查看了 IOS 的后台工作,发现 很多限制,例如与 Android 相比的持续时间或请求类型.在任何版本的 Android 中都是 100% 可能的(有一些调整).

I have looked at background work on IOS and found lots of limitation, like duration or type of requests, compared in Android. It is 100 percent possible in Android on any versions (with some adjustments).

这就是为什么我想知道这在 IOS 上是否完全可能,并且我们可能 2 小时持续时间的后台进程不会在任何情况下被杀死?当然,除了 IOS 系统的重启,我认为 不会恢复后台工作.

This is why I would like to know if this is completely possible on IOS and our background process with possibly 2 hours duration would not be killed at any conditions? Except of course the restart of IOS system, which would not resume background work, I assume.

另外,欢迎任何建议:) 保持坚强!

Also, would welcome any recommendations :) Stay strong!

推荐答案

你的提议在 iOS 上是不可能的.从一开始,应用程序就无法在打开套接字的情况下在后台运行.

What you propose is not possible on iOS. Since the beginning, apps have not been able to run in the background with a socket open.

这样做的理由是,设备上的无线电接口会保持通电状态并消耗大量电量.如果您可以在 Android 上实现这一点,它会遇到完全相同的问题.

The justification is that doing so keeps the radio interfaces on the device powered on and consumes a significant amount of power. If you can implement this on Android it has precisely the same issues.

从问题中不清楚您要解决什么问题:只有您选择的实施方式.

It's not clear from the question what problem you are trying to solve: only your chosen means of implementation.

可用的选项有:

后台应用刷新适用于需要定期背景刷新内容.

Background App Refresh is intended for apps which need to periodically background-refresh content.

您的应用会在有足够的电池寿命和连接性来执行它需要采取的任何操作时,在短时间内被唤醒(ISTR 15s).

Your app gets woken up for a short period of time (ISTR 15s) at a time when there is sufficient battery life and connectivity to preform whatever action it needs to take.

不能保证您会被唤醒或什么时候.在实践中,您可以期望的最多是每 15m,但经常会有很长的间隔,这可能是由请勿打扰和用户行为驱动的.

There are no guarantees that you will get woken up or when. In practice, the most you can expect is every 15m, but there are frequently long gaps, possibly driven by Do-not-disturb and user-behaviour.

URLSession 可以移交给 iOS 以在后台发生 - 专门用于下载大型内容项.

URLSession can be handed off to iOS to occur in the background - intended specifically for downloading large content item.

APNS 可用于唤醒您的应用程序(或者更有可能是 AppExtension).您需要定期发送通知.

APNS can be used to wake-up your app (or more likely, AppExtension). You would need to send a notification periodically.

同样,无法保证交付(间歇性连接).实际上,iOS 需要定期唤醒无线电接口并为其通电才能接收它们 - 如何以及何时发生这是一个块框.

Again, there are no guarantees about delivery (intermittent connectivity). Realistically, iOS needs to periodically wake up and power up the radio interface in order to receive them - how and when this happens is a block-box.

Firebase 等中间件可能会结合使用上述技术和 Websockets 来实现同步.

Middleware such as Firebase may use a combination of the technologies above and Websockets to achieve synchronisation.

这篇关于是否可以在后台实现不间断的 API 端点 ping?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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