Ich versuche, den Wert von backgroundTimeRemaining
zu überprüfen, aber ich bekomme eine sehr große Anzahl. Der Wert der Eigenschaft soll der 10 min entsprechen, und ich habe in der Apple Dokumentation here gelesen, dass ein solcher Wert groß ist, wenn die App im Vordergrund ist. Allerdings bekomme ich auch im Hintergrund einen großen Wert:iOS - backgroundTimeRemaining Wert zeigt nicht, was erwartet
- (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];
}
}
Was könnte ich vermissen? Vielen Dank im Voraus
Ich denke, die Hintergrund-Task wird nicht gestartet, bis das 'applicationDidEnterBackground' -Ereignis vollständig behandelt wurde. – Felix
Dann ... wie könnte ich den 'backgroundTimeRemaining' Wert anfordern? – AppsDev
versuchen Sie es innerhalb eines dispatch_async Block auf dem Hauptthread – Felix