0

I want to run this task every 5 Seconds even if the App is terminated

DispatchQueue.global(qos: .background).async {
   MapViewModel2().checkLocationAuthorization()
   let lat = UserDefaults.standard.double(forKey: Defaults.newLatitude)
   let long = UserDefaults.standard.double(forKey: Defaults.newLongitude)
   sendLocation(Latitude: lat, Longitude: long, id: 1)
}

I hope anyone can help me with this

  • hmm... if the app is terminated, how is it going to run the task? – timbre timbre Dec 20 '21 at 20:27
  • 1
    Please start here: [Choosing the Location Services Authorization to Request](https://developer.apple.com/documentation/corelocation/choosing_the_location_services_authorization_to_request), then read this: [Handling Location Events in the Background](https://developer.apple.com/documentation/corelocation/getting_the_user_s_location/handling_location_events_in_the_background) ; also, maybe remove the `swiftui` tag from your question. – magma Dec 20 '21 at 20:30
  • If you were able to run code even if your app is terminated, that would be a virus. – NicolasElPapu Dec 20 '21 at 21:52

0 Answers0