IOS App Gets the page when you return to the foreground from the background

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.