views:

45

answers:

1

I am developing an iPhone app that polls an internet web service. The poll rate will decay from once every 20 seconds to once every 15 minutes if the iPhone is sitting idle in a dock running my application. If the user taps the screen or begins moving around the UI I need to revive the polling rate back up to 20 seconds.

Is there a universal top level event handler where I can trap any user activity?

If not I propose to capture user activity at 4 major feature usage points such as any push and pop activity in my productivity app's nav controller bar.

+1  A: 

Try to implement -applicationDidBecomeActive and -applicationWillResignActive in your application delegate.
To handle all user activity you can also implement your custom UIWindow subclass and override -(void)sendEvent:(UIEvent*)event method there:

- (void)sendEvent:(UIEvent*)event {
   [super sendEvent:event];
   ... 
}

Edit: You may also listen to UIDeviceBatteryStateDidChangeNotification (available from SDK 3.0) to get notified when device is plugged/unplugged into power

Vladimir
@Vladimir: Thank you applicationDidBecomeActive seems to be part of the answer to my requirements but will the delegate trigger when the phone is sitting in a powered dock or hooked up to a usb cable? I cannot find a complete list of realworld events that trigger applicationWillResignActive. Are there any others appart from incoming call, sms, calendar event, auto lock and the manual lock button?
camelCase