Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "UIBackgroundTaskInvalid" mean?

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

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.

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.

like image 960
sota_m Avatar asked Dec 28 '22 03:12

sota_m


1 Answers

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

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.

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.

(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)

like image 52
grahamparks Avatar answered Jan 14 '23 00:01

grahamparks