Products Meimei to the small partners asked a demand, when the program from the background into the foreground, if it is the specified page, then pop-up prompt box.
Everyone first thought of the method is to control through the AppDelegate.h , the relatively complex step is the program into the background when the current page to store, and then enter the foreground from the background to determine whether it is a qualifying page, determine whether the box. That's the basic idea.
And then I started looking for new ways, and then I started a new practice.
The new method is better suited to the case of fewer matching pages, and a single uiviewcontroller is monitored
Method Source: http://www.shangxueba.com/jingyan/1844939.html
The above method puts the monitoring on the
Destruction monitoring is placed in
-(void) dealloc
However, there is a problem, because only when the page is really destroyed will be called-(void) Dealloc so there are many cases the page is not destroyed, but also does not appear in the current window (such as push new page entry, the old page will not be destroyed)
So I moved the location where the listener was added and destroyed.
-(void) Viewdidappear: (BOOL) animated{ [[Nsnotificationcenter defaultcenter] addobserver:self selector:@ Selector (somemethod:) name:uiapplicationdidbecomeactivenotification object:nil];} -(void) Viewdiddisappear: (BOOL) animated{ [[Nsnotificationcenter Defaultcenter] removeobserver:self];}
This will ensure that the listener is only invoked when the current page is displayed.
The problem is basically solved, there may be loopholes or better ways, welcome to add
IOS App Gets the page when you return to the foreground from the background