0

Hello I wanted to run a NSTimer on the main thread im not sure if they are run on the main thread by default or I have to do a special implementation ? thanks to anyone who could help

@interface RootViewController : UIViewController {

        NSTimer *minutePassed;
    }

    - (void)adViewDidLoad
    {

    minutePassed = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(callMinutedPassed) userInfo:nil repeats:NO];

    }

    -(void)callMinutePassed
    {
    NSLog("Minute Passed");
    }
Rob
  • 415,655
  • 72
  • 787
  • 1,044
isJulian00
  • 924
  • 2
  • 10
  • 24
  • 1
    This is the right way to schedule a timer. A few unrelated observations: https://gist.github.com/robertmryan/e8ec70f49f0c112ffdd7c4566eedc13e – Rob Mar 22 '19 at 01:05
  • if i have something like this and the app goes into background does the countdown keep counting to 60 seconds or does it get paused ?, minutePassed = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(callMinutePassed) userInfo:nil repeats:NO]; – isJulian00 Mar 25 '19 at 19:25
  • See https://stackoverflow.com/a/31642036/1271826 or https://stackoverflow.com/a/26405492/1271826 or https://stackoverflow.com/a/34497360/1271826... – Rob Mar 25 '19 at 19:42

1 Answers1

1

Documentation for scheduledTimer(timeInterval:target:selector:userInfo:repeats) states Creates a timer and schedules it on the current run loop in the default mode.. That means in your instance, that it is running on the main thread. I'm assuming when you say -(void)adViewDidLoad you mean -(void)viewDidLoad().

TimTwoToes
  • 695
  • 5
  • 10
  • if i have something like this and the app goes into background does the countdown keep counting to 60 seconds or does it get paused ?, minutePassed = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(callMinutePassed) userInfo:nil repeats:NO]; – isJulian00 Mar 25 '19 at 19:24