什么是“UIBackgroundTaskInvalid”意思? [英] What does "UIBackgroundTaskInvalid" mean?

查看:192
本文介绍了什么是“UIBackgroundTaskInvalid”意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发在后台运行的iPhone应用程序(iOS4),并参考Apple在以下网址上编写的完成背景中的有限长度任务

I'm developing iPhone app which runs in the background(iOS4), and refer "Completing a Finite Length Task in the Background" written by Apple at the following url

http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH5

然后我就能够实现后台任务了。
(当然,我看到该应用程序有10分钟的时间限制。)
但是,我仍然无法理解 bgTask = UIBackgroundTaskInvalid; (清单4-2中的第7,16行)表示。

Then I've been able to implement background tasks. (Of course, I see that application has 10min time limitaiton.) However, I still can't understand what "bgTask = UIBackgroundTaskInvalid;"(Line7,16 of Listing 4-2) means.

在我看来,从未达到上面显示的行。
因为之前有 endBackgroundTask:,后台任务将结束。
事实上,当我使用xcode调试器检查时,这个想法可能是真的,并且没有到达Line7,16。

In my opinion, the line shown above has never been reached. Because there is "endBackgroundTask:" before that and the background task will be ended. In fact, when I checked with xcode debugger, this thought may be true and not reach at Line7, 16.

如果是这样,这条线是多余的?
或者有没有理由要写?

If so, is this line redundant? Or is there any reason to have to be written?

我将不胜感激任何帮助。
提前致谢。

I would appreciate any help about this. Thanks in advance.

推荐答案

如果10分钟用完应用程序之前,则会调用块中的代码完成了它的后台任务。

The code in the block is called if the 10 minutes runs out before the application has completed its background task.

此块中的代码必须调用 endBackground:来表明情况已被确认并被接受通过申请 - 如果不是,申请将被终止。请注意,调用该方法不会终止应用程序 - 它只是向操作系统指示后台任务执行已完成。

The code in this block must call endBackground: to indicate the situation is acknowledged and accepted by the application - if it doesn't the application will be terminated. Note that calling the method doesn't terminate the application - it simply indicates to the OS that the background task execution has completed.

第二行只是重置 bgTask 为中性值,而不是将其设置为不再存在的任务的id。这是一个整洁的事情,而不是必要的。

The second line is simply to reset bgTask to a neutral value, rather than leaving it set id of a task that no longer exists. It's a tidiness thing rather than being essential.

(如果第二行直到下一个应用程序被预先执行,我不会感到惊讶,因为一旦执行后台结束应用程序没有任何CPU时间运行。但是没有测试过这个,但是)

(I wouldn't be surprised if the second line isn't executed until the application is next foregrounded, since once background execution ends the app doesn't get any CPU time to run. Haven't tested this, though)

这篇关于什么是“UIBackgroundTaskInvalid”意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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