I have a button which when pressed creates an object thing
. It then sleeps for ten seconds and then calls thing.go
which gets the application state like
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
Then following this question's answer and comments I check if the app is in the background, and if it is, it displays a local notification.
So I press the button and immediately press the home key to go to the main screen (thereby putting the app in the background)
However, I can tell that the if statement is returning false and is therefore not executing any code within (by putting an NSLog inside the if statement).
So my next thought process was to somehow display the date in the console using NSLog(state)
. Obviously I cannot do this.
So how can I display the applicationState to resolve my issue? Or is there another way I can check to see if the app is running in the background within this class's method?
Here is the go
function which is called inside the IBAction
when the button is pressed
-(void)go {
if (state == UIApplicationStateBackground) {
NSLog(@"App is in background");
}
}
Here is the IBAction
which is linked to the button, i.e. runs when button is pressed
- (IBAction)button_help {
myclass* thingy = [[myclass alloc] init];
sleep(10);
thingy.go;
}