Under normal circumstances, the following two methods are implemented in the Appdelegate to enable monitoring to resume from the background to the foreground
[CPP]
-(void) Applicationdidenterbackground: (uiapplication *) application
{
Log4info (@ "---applicationdidenterbackground----");
Go backstage
}
-(void) Applicationdidbecomeactive: (uiapplication *) application
{
NSLog (@ "---applicationdidbecomeactive----");
Access to Reception
}
-(void) Applicationdidenterbackground: (uiapplication *) application
{
Log4info (@ "---applicationdidenterbackground----");
Go backstage
}
-(void) Applicationdidbecomeactive: (uiapplication *) application
{
NSLog (@ "---applicationdidbecomeactive----");
Access to Reception
}
But how does a single Uiviewcontroller listen?
In the-viewdidload method, add the Code listener notification
[CPP]
[[Nsnotificationcenter Defaultcenter] Addobserver:self
Selector: @selector (somemethod:)
Name:uiapplicationdidbecomeactivenotification Object:nil];
[[Nsnotificationcenter Defaultcenter] Addobserver:self
Selector: @selector (somemethod:)
Name:uiapplicationdidbecomeactivenotification Object:nil];
Don't forget to remove the listener from the-dealloc:
[CPP]
[[Nsnotificationcenter Defaultcenter] removeobserver:self];
[[Nsnotificationcenter Defaultcenter] removeobserver:self];