Welcome to my Programming Blog...

I am currently working on a couple of projects: An original game called "Implosion" which I am porting from Flash to the iPad, and a remake of Q*bert in Python (pygame), as part of the class I am teaching. Please feel free to use the "Labels" (at right) to follow a specific project or theme. If you are one of my Python students, I recommend that you check out the Python thread.

Saturday, October 16, 2010

#VTM_iPhone notes on multitasking presentation

Here are my notes on jeff lamarche's presentation, "multitasking the iPhone sdk way"


One of the biggest complaints from developers about early ios.

Actually, it had multitasking from day one - lots of first party apps running once.

Of course, apple just does this to be mean.

Real reason - battery impact and foreground application responsiveness

The audience at this convention - we're the outliers. Most people see computers as an obstacle.

"Devices for the rest of us."

Myth: with ios 4, we have "true multitasking." but don't use it for its own sake if you don't really need them. Will a push notification work?

Basically, you can maintain state, and can't do much (if any) processing in background.

Legacy apps can be set to opt out of multitasking. In info.plist.

Four types of background tasks - background audio, voip, navigation & location tracking, task completion

Playing nicely: application lifecycle
Before 4.0: not running, inactive, active
application delegate fires when state changes
Active --> inactive: applicationWillResignActive
Active ->not running: applicationWillTerminate
At 4.0:
States
foreground: active, inactive
Background: suspended, active
Not running

If you want to keep running in background, keep your (over)head low.

ApplicationDidEnterBackground
ApplicationWillEnterForeground

Problem: if you are in background, will not get notification if the program is killed. Issues for persistence.
--------
Background
Should not run code that does drawing or leverages the gnu
Should close any network listeners
Stop advertising or looking for bonjour services
But make sure you resume when you return tho the foreground

Generally, should dismiss alerts, action sheets.
If multiple buttons, pick the non-destructive option.

Background - hide sensitive info in UI

Shouldn't access shared data APIs - calendar, address book, music/media library

Hint: instruments works fine with background applications - in fact, a very good idea.

You can still set base SDK to 4.x and still target 3.0. Delegate methods just don't get called.

Don't check hardware or OS version!

Task completion API - general purpose. Can request to keep running - to finish a process. Must finish in given time limit, or will be killed. You do have a chance to clean up and save.

How long? Not documented. Simulator gives 5 minutes. You don't have to wait for app event to request time.

See handout for sample code.

Uses blocks.... Get over it, and they are coming. Suddenly, they will click.

Nb: if it's long enough to require task completion, it needs to be off the main thread.

Background audio

It's opt-in. Must identify that you use them in your info.plist file

Your background app will override foreground audio!
Background apps using radios can drain battery. Be sure to close down the connection.
The background audio can also record sound!
Must implement avaudiosessiondelegate - should implement begin interruption and end interruptooonwithflags

In, must override canBecomeFirstResponder to return YES.

Apple has put a lot of thought about this. Balance between developers and users.

If you can't find a way around this: bugreport.apple.com

Stop drawing? Mostly automatic. You do (seem) to get some time after the notification arrives that the app will go inactive

Jeff_lamarche@Mac.com

- Posted using BlogPress from my iPad

No comments:

Post a Comment