Ich entwickle eine App, in der ich den Standort des Benutzers regelmäßig aktualisieren muss, aber ich kann keine Standortaktualisierung erhalten, wenn die App gesperrt ist im Hintergrund laufen. Ich habe auch Hintergrund Standort Update in Fähigkeiten aktiviert.Wie bekomme ich eine Standortaktualisierung in ios mit swift, auch wenn die App im Hintergrund läuft?
viewDidLoad Code:
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.allowsBackgroundLocationUpdates = true
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
let user=FIRAuth.auth()?.currentUser?.displayName
if(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways || CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse){
locationManager.requestLocation()
location=locationManager.location
locationManager.startUpdatingLocation()
locationManager.startMonitoringSignificantLocationChanges()
//updating to database
ref.child("\(user!)/lat").setValue(location.coordinate.latitude)
ref.child("\(user!)/long").setValue(location.coordinate.longitude)
//location=locationManager.location
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
location=locations[locations.count-1]
}
Hoffnung diese Antwort würde Ihnen helfen, http://stackoverflow.com/questions/5323634/ios-application-executing-tasks-in-background – iMuzahid
ich denke, diese Verbindung für Sie hilfreich http://stackoverflow.com/questions/28503990/ios-running-background-task-for-update-user-location-using-swift – Ram
@Prakhar bro müssen Sie über diese https://github.com/ voyage11/Location –