gpt4 book ai didi

iOS 后台任务会在前台完成吗?

转载 作者:可可西里 更新时间:2023-10-31 23:13:20 26 4
gpt4 key购买 nike

如果我使用此方法运行任务,但将应用程序保持在前台,当应用程序处于前台时是否会调用 expirationHandler?

我每次进后台都是用这个来启动定位服务的,但是有时候用户进了后台又立马回到app,这个会调用expirationHandler吗?

func beginBackgroundTask(expirationHandler handler: (() -> Void)? = nil) -> UIBackgroundTaskIdentifier

最佳答案

文档说:

A handler to be called shortly before the app’s remaining background time reaches 0. Use this handler to clean up and mark the end of the background task. Failure to end the task explicitly will result in the termination of the app. The system calls the handler synchronously on the main thread, blocking the app’s suspension momentarily.

https://developer.apple.com/documentation/uikit/uiapplication/1623031-beginbackgroundtaskwithexpiratio

似乎在前台模式下没有调用过期处理程序。等待很长时间后,我进入了后台模式,然后在约 170 秒后为所有先前报告的后台任务调用过期处理程序。

关于iOS 后台任务会在前台完成吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41585488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com