I need to know when an App is in Foreground, it is in active state or inactive state ?
If my App is in inactive state I need to fire the Logout Protocol and destroy the current user's session,
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"App is not active logout success");
}
Is there any appDelegate method which tell me that app is in inactive state, any code example will help me a lot.
If need work with "NSNotificationCenter", in which class can I add the code and who will be observer.
inactive. The app is running in the foreground but isn't receiving events.
Click on the iOS application from the left-hand side menu under the App store tab (see below screenshot). Here you will find the application publish status. If the application is in LIVE, then the status is “Ready for sale” otherwise it is in “waiting for review”/ “In review” / “Rejected” (if any rejection).
To detect if an iOS application is in background or foreground we can simply use the UIApplication just like we can use it to detect many other things like battery state, status etc. The shared. application state is an enum of type State, which consists of the following as per apple documentation.
Inactive - The app is running in the foreground, but not receiving events. An iOS app can be placed into an inactive state, for example, when a call or SMS message is received. Active - The app is running in the foreground, and receiving events.
To test for the state you can do something like:
[[UIApplication sharedApplication] applicationState]==UIApplicationStateInactive
or
[[UIApplication sharedApplication] applicationState]==UIApplicationStateActive
If you want to be notified you can do:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yourselector:)
name:UIApplicationDidBecomeActiveNotification object:nil];
or
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yourselector:)
name:UIApplicationDidEnterBackgroundNotification object:nil];
You can do other notifications too (from https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/):
UIApplicationDidBecomeActiveNotification UIApplicationDidChangeStatusBarFrameNotification UIApplicationDidChangeStatusBarOrientationNotification UIApplicationDidEnterBackgroundNotification UIApplicationDidFinishLaunchingNotification UIApplicationDidReceiveMemoryWarningNotification UIApplicationProtectedDataDidBecomeAvailable UIApplicationProtectedDataWillBecomeUnavailable UIApplicationSignificantTimeChangeNotification UIApplicationUserDidTakeScreenshotNotification UIApplicationWillChangeStatusBarOrientationNotification UIApplicationWillChangeStatusBarFrameNotification UIApplicationWillEnterForegroundNotification UIApplicationWillResignActiveNotification UIApplicationWillTerminateNotification UIContentSizeCategoryDidChangeNotification
If you want to use the app delegate, you can use:
- (void)applicationDidEnterBackground:(UIApplication *)application {}
or
- (void)applicationDidBecomeActive:(UIApplication *)application {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With