How to keep NSTimer alive in Background on iOS 7?

后端 未结 4 602
情书的邮戳
情书的邮戳 2021-01-01 03:35

I have created Application which runs NSTimer in Background. I used the Location manager to run the NSTimer in background,

I used below link to run NSTimer in backgr

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 04:12

    NSTimer *currentCycleTimer;
    
    UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
    UIApplication *app = [UIApplication sharedApplication];
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    [app endBackgroundTask:bgTask];
    }];
    [currentCycleTimer invalidate];
    currentCycleTimer=nil;
    secondsLeft = 120;
    currentCycleTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self        selector:@selector(Countdown) userInfo:nil repeats: YES];
    
    -(void) Countdown
    {
      [currentCycleTimer invalidate];
      currentCycleTimer=nil;
    }
    

提交回复
热议问题