iOS版 - backgroundTimeRemaining值不显示期望是什么 [英] iOS - backgroundTimeRemaining value not showing what expected
问题描述
我想检查 backgroundTimeRemaining
的价值,但我得到一个非常大的数字。该属性的值被认为是相应于10分钟aprox的,而苹果文档中<一个i`ve读href=\"http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html\">here这样的值大时,应用程序是在前台。不过,我得到一个较大的值,即使在背景:
I'm trying to check the value of backgroundTimeRemaining
, but I get a very large number. The value of the property is supposed to be the corresponding to 10 min aprox, and i`ve read in Apple documentation here that such value is large when the app is in the foreground. However, I get a large value even when in background:
- (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];
}
}
还有什么我缺少什么?在此先感谢
What could am I missing? Thanks in advance
推荐答案
根据X code运行时,看门狗定时器被禁止。
The watchdog timer is disabled when running from Xcode.
我无关运行时,大多得到合理的值(即600),但我仍然得到偶尔的怪异值。
I mostly get sensible values (ie. 600) when running unconnected, but I still get the occasional weird value.
这篇关于iOS版 - backgroundTimeRemaining值不显示期望是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!