0

I would like to know how to run a clock or timer that works even the app is closed. I have this code in my ViewDidLoad:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"hh:mm:ss"];
    NSString *time = [formatter stringFromDate:[NSDate date]];

This code only works when the user open up the view. But I want to know how to create a clock that works all the time even when the phone is locked. I just need some guide. Any help would be very much appreciated. Thanks.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ty Lertwichaiworawit
  • 2,950
  • 2
  • 23
  • 42

1 Answers1

2

There are two ways to do this. 1) register your app as one of the Apple approved background apps, of which simple timer apps are not, and 2) set a local notification using your time.

coneybeare
  • 33,113
  • 21
  • 131
  • 183