无法启动beginBackgroundTask swift 3 [英] can't start beginBackgroundTask swift 3

查看:157
本文介绍了无法启动beginBackgroundTask swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我被卡住了,但是我正在尝试启动后台任务(XCode8,迅速3)

Sorry I am stuck, but I am trying to start background task (XCode8, swift 3)

此处的示例: 在AppDelegate.swift中:

func applicationDidEnterBackground(_ application: UIApplication) {
    var bgTask: UIBackgroundTaskIdentifier = 0;
    bgTask = application.beginBackgroundTask(withName:"MyBackgroundTask", expirationHandler: {() -> Void in
        print("The task has started")
        application.endBackgroundTask(bgTask)
        bgTask = UIBackgroundTaskInvalid
    })
}

该应用程序从未显示任务已开始"消息.我在做什么错了?

The app has never shown "The task has started" message. What am I doing wrong?

推荐答案

在后台运行一段时间(通常为5分钟左右)后,将调用过期处理程序块. 如果您的后台任务要花费大量时间来完成,那么这将用于编写清理逻辑.

The expiration handler block gets called after a period of time in background (usually 5 minutes or so). This is meant to be used to write the clean up logic if in case you background task is taking a lot of time to complete.

您的代码没有错,您只需要在后台等待 即可使后台任务过期.

There is nothing wrong with your code, you just need to wait in the background for the background task to expire.

这篇关于无法启动beginBackgroundTask swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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