NSURLSession后台任务:何时调用handleEventsForBackgroundURLSession:complementHandler? [英] NSURLSession background tasks: when to call the handleEventsForBackgroundURLSession: completionHandler?

查看:60
本文介绍了NSURLSession后台任务:何时调用handleEventsForBackgroundURLSession:complementHandler?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NSURLSession上传多个视频文件.

I'm using an NSURLSession to upload multiple video files.

似乎在每个任务完成之后,多次调用了 application:handleEventsForBackgroundURLSession:completionHandler:方法.我存储传递给此方法的completionHandler,以便以后可以调用它.

The application:handleEventsForBackgroundURLSession:completionHandler: method is called several times, seemingly after each task completes. I store the completionHandler that's passed to this method so that I can invoke it later.

我的问题是:每次调用上述应用程序委托方法时,我都要调用它吗?还是仅在后台会话的 [任务计数] == 0 时才调用它?当我执行后者时,该应用程序将在控制台中崩溃,并在控制台中显示以下信息:

My question is this: do I invoke it each time the above application delegate method is called? Or do I invoke it only when my background session's [tasks count] == 0? When I do the latter the app crashes in the background with this info in the console:

Application Specific Information:
<BKNewProcess: 0x134d48400; com.vimeo; pid: 2141; hostpid: -1> has active assertions beyond permitted time: 
{(
    <BKProcessAssertion: 0x134d49500> id: 1679-3230372B-D4E5-44A1-A8DD-221CA8E6EECE name: com.apple.nsurlsessiond.handlesession com.vimeo.app.BackgroundSessionIdentifier process: <BKNewProcess: 0x134d48400; com.vimeo; pid: 2141; hostpid: -1> permittedBackgroundDuration: 30.000000 reason: backgroundDownload owner pid:1679 preventSuspend  preventThrottleDownUI  preventIdleSleep  preventSuspendOnSleep 
)}

我已经阅读了许多关于后台会话及其复杂性的StackOverflow和博客文章,并且看到有关上述问题的信息相互矛盾.

I have read many StackOverflow and blog posts on background sessions and their intricacies, and I see conflicting information regarding the above question.

在此先感谢您的帮助.

推荐答案

URLSessionDidFinishEventsForBackgroundURLSession 的文档说要在那里调用它.我之所以这样做,只是因为他们说过,而且我还没有看到任何相关的问题.

The docs for URLSessionDidFinishEventsForBackgroundURLSession say to call it there. I've been doing that just because they said to and I haven't seen any related problems.

这篇关于NSURLSession后台任务:何时调用handleEventsForBackgroundURLSession:complementHandler?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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