CLLocationManager Stop Location Acquisition Baggrand Task From When

Asked 2 years ago, Updated 2 years ago, 49 views

I am writing a program that takes a location in CLLocationManager on Swift and sends it to the server.
There is no problem with the operation itself, but after moving to the background, location acquisition and server information transmission will be working for a while, but server information will not be transmitted at any time.
Is there any reason such as time limit?If you know how to deal with it, I would appreciate it if you could let me know.

Attach the appropriate source.

override func viewDidLoad(){
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from anib.
    longitude=CLLocationDegrees()
    latitude=CLLocationDegrees()
    keido.text=String (stringInterpolationSegment: longitude)
    ido.text=String(stringInterpolationSegment:latitude)

    lm = CLLocationManager()
    lm.delegate=self
    lm.requestAlwaysAuthorization()
    lm.desiredAccuracy=kCLLocationAccuracyBest
    lm.distanceFilter=5
    lm.startUpdatingLocation()
}

funclocationManager(manager:CLLocationManager!, didUpdateToLocation newLocation:CLLocation!, fromLocation oldLocation:CLLocation!){
        longitude = newLocation.coordinate.longitude
        latitude = newLocation.coordinate.latitude
        keido.text=String (stringInterpolationSegment: longitude)
        ido.text=String(stringInterpolationSegment:latitude)
    varmyUrl:NSURL=NSURL(string:NSSstring(format:"http://(mask)/locationget.php?id=xxxx&longitude=%@&latitude=%@", String(stringInterpolationSegment:longitude), String(stringInterpolationSegment:String)!)
    varmyRequest —NSURLRequest = NSURLRequest (URL: myUrl)
    NSURLConnection.sendAsynchronousRequest (myRequest,queue:NSOperationQueue.mainQueue(), completionHandler:self.getHttp)
        NSLog ("Update")
}

swift xcode

2022-09-30 17:20

1 Answers

There is a property called pauseLocationUpdatesAutomatically, which is default and true.If this is true, it seems that the update will stop when it is judged that the location information is unlikely to change (for example, I have been staying in the same place for a while because I am eating).

CLLocationManager Class Reference


2022-09-30 17:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.