Warum zeigt die Protokollierung von Hintergrundtimeremaining eine falsche/große Zahl, obwohl die App in den Hintergrund IOS

Programmierung für iOS
Anonymous
 Warum zeigt die Protokollierung von Hintergrundtimeremaining eine falsche/große Zahl, obwohl die App in den Hintergrund

Post by Anonymous »

Ich habe meine uiapplication.shared.backgroundTimeremaining abhängig, aber die Zahl ist riesig. Es sind fast 200 Ziffern. < /p>

Code: Select all

 os_log("Lat: %f | Long:  %f | RemainingTime: %f ", log: log, type: .default, location.coordinate.latitude, location.coordinate.longitude, UIApplication.shared.backgroundTimeRemaining)
< /code>

Ich dachte, mit dem Format meiner Protokollierung stimmt etwas nicht, also habe ich auch versucht, einen Haltepunkt zu platzieren und zu drucken, aber die Nummer, die es protokolliert, ist die gleiche riesige Zahl. Ich habe mich auch mit dieser Frage befasst, die eine faire Erklärung hat. Wenn Ihre App im Vordergrund ist, wäre die Zeit so groß. Aber ich sehe diese Nummer immer noch, auch wenn ich die App in den Hintergrund verschoben habe.  179769313486231570814527423731704356798070567525844996598917476803157260780028 5387605895586327668781715404589535143824642343213268894641827684675467035375169860 499105765512820762454900903893289440758685084551339423045832369032229481658085593 32123348274797826204144723168738177180919299881250404026184124858368.000000 
< /blockquote>

Gesamtcode: < /p>

import UIKit
import CoreLocation
import os.log
import MapKit

class ViewController: UIViewController, CLLocationManagerDelegate{

lazy var locationManager : CLLocationManager = {
var manager = CLLocationManager()
manager.delegate = self

manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
manager.distanceFilter = 1
manager.pausesLocationUpdatesAutomatically = true
manager.allowsBackgroundLocationUpdates = true
manager.requestAlwaysAuthorization()
manager.startUpdatingLocation()
return manager
}()

var lastLocation : CLLocation?

var mapView : MKMapView?

let log = OSLog(subsystem: "XYZ.LocationAppSubSystem", category: "dumbo")

override func viewDidLoad() {
super.viewDidLoad()

if locationManager.location != nil{

}else {

DispatchQueue.main.async {
self.locationManager.startUpdatingLocation()
}

}
os_log("view was Loaded", log: log, type: .error)

mapView = MKMapView(frame: UIScreen.main.bounds)
mapView?.showsUserLocation = true
view.addSubview(mapView!)

}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

guard let location = locations.last else {
return
}
lastLocation = location
//        let date = Date().description(with: Locale.current)

os_log("Lat: %{public}f | Long:  %{private}f | RemainingTime: %{public}f ", log: log, type: .default, location.coordinate.latitude, location.coordinate.longitude, UIApplication.shared.backgroundTimeRemaining)

}

func locationManagerDidPauseLocationUpdates(_ manager: CLLocationManager) {
os_log("locationManager was paused", log: log)

let location = lastLocation

os_log("Lat: %{public}f | Long:  %{private}f | RemainingTime: %{public}f ", log: log, type: .default, (location?.coordinate.latitude)!, (location?.coordinate.longitude)!, UIApplication.shared.backgroundTimeRemaining)

}

func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
os_log("Region was exited", log: log)
}

func createRegion(location: CLLocation) {

let radius = 3.0

let region = CLCircularRegion(center: location.coordinate, radius: radius, identifier: "didPauseLocationUpdates")
region.notifyOnExit = true
region.notifyOnEntry = false

locationManager.startMonitoring(for: region)
}

func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error) {
if region?.identifier == "didPauseLocationUpdates"{
os_log("Main Region was Failed to be created", log: log)
}else{
os_log("Other regions were checked ", log: log)
}
}

}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post