November 2013
Intermediate to advanced
576 pages
19h 3m
English
After a background task ID has been obtained, the actual work to be done in the background can commence. In the performBackgroundTask method some variables are set up to know where to start counting, to keep count of iterations, and to know when to stop. A reference to NSUserDefaults standardUserDefaults is established to retrieve the last counter used, and store the last counter with each iteration.
NSInteger counter = 0;NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];NSInteger startCounter =[userDefaults integerForKey:kLastCounterKey];NSInteger twentyMins = 20 * 60;
The background task for the sample app is trivial—it puts the thread to sleep for a second in a ...
Read now
Unlock full access