Reputation:
My app is constantly polling a web server. In the interest of reducing the data usage for the user and to reduce the load on my server I would likely to check when the app has the screen locked and when the app is in background mode so I can stop the unnecessary web traffic.
Is there a handy method for check the state of the app?
Many Thanks -Code
Upvotes: 0
Views: 612
Reputation: 491
Couldn't you just put a method inside your
-(void)applicationDidEnterBackground:(UIApplication *)application
?
Also if you aren't wanting your app to do stuff in the background you could add the key in your plist to tell the app to close when the user hits the home button.
Upvotes: 0
Reputation: 20153
How about UIApplication's applicationState property? Its return value is an enum:
typedef enum {
UIApplicationStateActive,
UIApplicationStateInactive,
UIApplicationStateBackground
} UIApplicationState;
And, being a singleton, you can access it from anywhere via the +sharedApplication
class method.
Upvotes: 1