ios swift请求框架_Swift iOS BackgroundTasks框架-只需4个步骤即可刷新后台应用程序

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)和新闻应用程序。

Image for post
illustration of foreground and background task; Copy from WWDC 2019 presentation slide
前台和后台任务的插图; 从WWDC 2019演示幻灯片中复制

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和应用程序端之间的后台任务请求。 BGAppRefreshTaskBGProcessingTask是后台任务的两种可用类型。 BGAppRefreshTask可以有30秒完成工作,而BGProcessingTask可以有超过一分钟的时间 。 对于旧的应用程序(_:performFetchWithCompletionHandler :) ,处理方法有所不同。

Background task execution depends on several conditions, including:

后台任务的执行取决于多种条件,包括:

  1. User permission on “Background App Refresh”

    用户对“后台应用程序刷新”的权限
  2. Power supply from charger

    充电器供电
  3. 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.

如果分别使用了BGAppRefreshTaskBGProcessingTask ,请转到应用程序目标的“ 后台模式 ”会话,并选中“ 后台获取 ”和“ 后台处理 ”选项。

Image for post
Capability session of app target
应用目标的功能会话

步骤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并添加“ 允许的后台任务调度程序标识符 ”属性以及BGAppRefreshTaskRequestBGProcessingTaskRequest的标识符

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值