IOS in the view controller to determine the application's foreground background switch Uiviewcontroller

Source: Internet
Author: User

1. When the user clicks the home button to apply back to the background again click into the foreground in the Uiviewcontroller controller how to get related events?

2. Requirements

(1) Nstimer The app goes back 10 seconds to 10 minutes will stop (10 minutes or so the general application will be killed) but as long as the background of this nstimer run is sloppy, so I want to stop it when the application into the background

(2) The program supports the background download, when the user stops in the Download management interface, then the user clicks the Home button to make the program run in the background, and so on when the user returns to the program, the download management interface needs to display the latest download progress. (It takes a long time to start the backend service, we only talk about two events in Uiviewcontroller)

3. Implement

This is accomplished using notifications

// Increased monitoring [[Nsnotificationcenter defaultcenter] addobserver:self                                         selector: @selector (apphasgoneinforeground:)                                      Name:uiapplicationwillenterforegroundnotification                                           object: nil];   // Don't forget to delete the listener [[Nsnotificationcenter Defaultcenter] removeobserver:self];   
Uiapplicationdidenterbackgroundnotification  // Go backstage // go back to the program

Very convenient is not, before I also silly in appdelegate inside judge many conditions to brush page, now want to, that will I really a dick silk, haha

IOS determines the foreground background switch of the application in the View controller Uiviewcontroller

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.