ios swift请求框架
IOS allows app to refresh it content even when it is sent to background. iOS can intelligently study the user’s behaviour and schedule background tasks to the moment right before routine usage. It is useful for app to retrieve the latest information from its server and display to user right when app is resumed to foreground. Examples are social media app (Facebook, Instagram & WhatsApp) and news app.
I OS允许应用程序刷新内容,即使将其发送到后台也是如此。 iOS可以智能地研究用户的行为并将后台任务安排在常规使用之前的时刻。 当应用程序恢复到前台时,它对于从其服务器检索最新信息并向用户显示权限很有用。 例如社交媒体应用程序(Facebook,Instagram和WhatsApp)和新闻应用程序。
Since iOS 13, Apple has added a new framework — BackgroundTasks — to handle the background task request between iOS and app side. BGAppRefreshTask & BGProcessingTask are the two available types of background task. BGAppRefreshTask can have 30 seconds to complete its job and BGProcessingTask can have more than a minute. The handling method is different for the old application(_:performFetchWithCompletionHandler:) way.
从iOS 13开始,Apple添加了一个新框架-BackgroundTasks-处理iOS和应用程序端之间的后台任务请求。 BGAppRefreshTask和BGProcessingTask是后台任务的两种可用类型。 BGAppRefreshTask可以有30秒完成工作,而BGProcessingTask可以有超过一分钟的时间 。 对于旧的应用程序(_:performFetchWithCompletionHandler :) ,处理方法有所不同。
Background task execution depends on several conditions, including:
后台任务的执行取决于多种条件,包括:
- User permission on “Background App Refresh” 用户对“后台应用程序刷新”的权限
- Power supply from charger 充电器供电
- Network connectivity 网络连接
Let’s see how to setup the Background App Refresh and understand the details on using it!
让我们看看如何设置“后台应用刷新”并了解使用它的详细信息!
后台应用程序刷新的4个步骤 (4 Steps to Background App Refresh)
步骤1)为应用程序目标启用后台模式 (Step 1) Enable Background Modes for app target)
Go to the “Background Modes” session of the app target and check “Background fetch” and “Background processing” options if BGAppRefreshTask and BGProcessingTask are used respectively.
如果分别使用了BGAppRefreshTask和BGProcessingTask ,请转到应用程序目标的“ 后台模式 ”会话,并选中“ 后台获取 ”和“ 后台处理 ”选项。
步骤2)添加“ 允许的后台任务计划程序标识符 ” (Step 2) Add “Permitted background task scheduler identifiers”)
Go to info.plist
and add “Permitted background task scheduler identifiers” property with identifiers for BGAppRefreshTaskRequest and BGProcessingTaskRequest.
转到info.plist
并添加“ 允许的后台任务调度程序标识符 ”属性以及BGAppRefreshTaskRequest和BGProcessingTaskRequest的标识符 。