#import "ViewController.h" @interface ViewController () @end @implementation ViewController -(IBAction)fivemin:(id)sender{perVrem = 300; TimerDisplay.text = [NSString stringWithFormat:@"05:00"];} -(IBAction)tenmin:(id)sender{perVrem = 600; TimerDisplay.text = [NSString stringWithFormat:@"10:00"];} -(IBAction)fifteen:(id)sender{perVrem = 900; TimerDisplay.text = [NSString stringWithFormat:@"15:00"];} -(IBAction)Start:(id)sender{ secondsCount = perVrem; countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeRun) userInfo:nil repeats:YES]; } -(IBAction)Stop:(id)sender{ [countdownTimer invalidate]; } -(IBAction)Reset:(id)sender{ [countdownTimer invalidate]; countdownTimer = nil; secondsCount = 0; TimerDisplay.text = [NSString stringWithFormat:@"00:00"]; } -(void)timeRun{ secondsCount = secondsCount - 1; int minuts = secondsCount / 60; int seconds = secondsCount - (minuts * 60); NSString *timerOutput = [NSString stringWithFormat:@"%2d:%.2d", minuts, seconds]; TimerDisplay.text = timerOutput; if (secondsCount == 0) { [countdownTimer invalidate]; countdownTimer = nil; AudioServicesPlaySystemSound(PlaySoundID); } } - (void)viewDidLoad { [super viewDidLoad]; NSURL *SoundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle ] pathForResource:@"pip" ofType: @"mp3"]]; AudioServicesCreateSystemSoundID((__bridge CFURLRef) SoundURL, &PlaySoundID); self.bannerView.adUnitID = @"ca-app-pub-4103490159107800/4026951578"; self.bannerView.rootViewController = self; [self.bannerView loadRequest:[GADRequest request]]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end 

    1 answer 1

    In ios, the application does not live in the background itself. It seems that now you can request a maximum of 3 minutes so that it still hangs, and if you need more, then it is necessary that the application’s functionality matches the task that is allowed to hang in the background longer, for example, tracking of the locale or playing music.

    https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

    To get your right three minutes, you can write this under the delegate app:

     - (void)applicationDidEnterBackground:(UIApplication *)application { __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithName:@"Keep online" expirationHandler:^{ [application endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ while (application.applicationState != UIApplicationStateActive) { [NSThread sleepForTimeInterval:1.0]; } [application endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }); } 
    • Where does the information about 3 minutes come from? - Max Mikheyenko
    • Experimentally, from personal experience, the old axes were 10 minutes, then reduced. Well, I think that this time is documented, and by default it can be any, on the choice of the axis, but in fact for each version of the axis it is fixed, and for 9 it was 3 minutes, if my memory serves me. stackoverflow.com/questions/28275415/… - markov