6

我正在尝试检查 的值backgroundTimeRemaining,但我得到了一个非常大的数字。该属性的值应该对应于大约 10 分钟,我在 Apple 文档中读到,当应用程序处于前台时这个值很大。但是,即使在后台,我也能获得很大的价值:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
   bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
      [application endBackgroundTask:bgTask];
      bgTask = UIBackgroundTaskInvalid;
   }];

   // Background task
   NSTimeInterval timeRemaining = [UIApplication sharedApplication].backgroundTimeRemaining;
   NSLog(@"Background time remaining: %f seconds (%d mins)", timeRemaining, (int)(timeRemaining / 60));

   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
      NSTimeInterval timeRemaining = [UIApplication sharedApplication].backgroundTimeRemaining;
      NSLog(@"Background time remaining: %f seconds (%d mins)", timeRemaining, (int)(timeRemaining / 60));

      // Perform task

      // Finished
      if (bgTask != UIBackgroundTaskInvalid) {
         [application endBackgroundTask:bgTask];
         bgTask = UIBackgroundTaskInvalid;
      }
  });

  // Start location manager
  if ([CLLocationManager locationServicesEnabled]) {          
     [locationManager startUpdatingLocation];
  }
}

我能错过什么?

4

1 回答 1

3

从 Xcode 运行时,看门狗定时器被禁用。

在未连接的情况下,我主要得到合理的值(即 600),但我仍然偶尔会得到奇怪的值。

于 2013-08-15T15:29:25.107 回答