当应用程序收到 Pushkit Voip 推送时,它会获得多少运行时间?

How much runtime does an app get when it receives a Pushkit Voip Push?

如果某个应用程序在后台运行或终止并且它收到 voip 推送,那么 OS 将启动它并 运行 它。

文档说:

"Your app is given runtime to process a push, even if your app is operating in the background."

有人知道这个运行时间有多长吗?应用程序是否可以找出剩余时间?

如果一个应用程序在前台并移动到后台,那么如果它使用 beginBackgroundTask() 等,它可以获得 30 秒的执行时间。

我进行了实验,发现如果应用程序已经在后台时向应用程序发送静默推送,那么该应用程序也可以在这种情况下使用 beginBackgroundTask() 并且它也有 30 秒的时间来当它收到推送时执行并做一些事情(它可以使用 UIApplication.shared.backgroundTimeRemaining 查看剩余时间。)

但是如果发送 Voip 推送而不是静默推送,则 beginBackgroundTask() 功能将不起作用(当然因此 UIApplication.shared.backgroundTimeRemaining 不能用于确定剩余执行时间),但是应用程序可以 运行 在后台执行一些 activity (这是上面引用的文档说它可以做的)。

所以重复这个问题 - Apple 是否记录了它在收到 Voip 推送时到达 运行 的时间?该应用程序可以找出剩余时间吗?或者得到执行时间即将到期的警告?

1) Apple 是否记录了收到 Voip 推送时它到达 运行 的时间?

不,Apple 在文档中没有此信息

2) app可以查询剩余时间吗?

没有。当应用程序启动时,它假设在后台模式下执行。您将有大约 30 秒的时间来执行必要的任务。

3) 或者得到执行时间即将到期的警告?

没有。至少没有记录的方法来做到这一点。

Apple 是否记录了它收到 Voip 推送时到达 运行 的时间?

No, There is no official documents available about how much time you have got, When received VoIP Push notification.

As per my personal experience, You will extends time up to 45 Sec using long duration sound file if required.

APP可以查询剩余时间吗?或者得到一些执行时间即将到期的警告?

No, There is no official documents or do not available any delegate method to find how much time remaining.

I have faced same issue, I was overcome above issue using multiple VoIP Push with different parameters. You can achieved it as below.

根据我的要求,我必须在用户收到通知时显示通知 新来电。如果用户没有接听电话,那么我必须发出新的通知 对于未接来电。我是这样实现的。

1) Generate local notification when received first VoIP Push. 

2) Cancel already generated notification and generate new missed call notification for user.

我不确定,但如果工作的话你也可以使用计时器。

一旦您在 didReceiveIncomingPushWithPayload 中获得 VOIP 推送负载,您就必须使用声音文件安排本地通知,根据声音文件持续时间,您的应用程序将在后台唤醒(当它处于终止模式时)。

声音文件最多允许 30 秒,没有进程知道有多少时间未决。

UIApplication.shared.backgroundTimeRemaining

无法获取剩余时间,因为应用尚未从 AppDelegate 唤醒,它在后台通过 VOIP 委托方法唤醒。

参考更多详情。

https://github.com/hasyapanchasara/PushKit_SilentPushNotification