Trapping general UI activity within an iPhone app
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 capt开发者_运维问答ure user activity at 4 major feature usage points such as any push and pop activity in my productivity app's nav controller bar.
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
精彩评论