Is it possible to invoke didUpdateLocations
inside the Timer
? I mean..
_timer = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(_:didUpdateLocations:)), userInfo: nil, repeats: true)
Is that going to work ? If yes then it is going to update location every 10 seconds ?
You can't invoke didUpdateLocations. If you want frequent updates, your best choice is the Standard location service:
The standard location service is most appropriate for apps that
deliver location-related information directly to the user but it may
be used by other types of apps too. To start the service, configure
the desiredAccuracy and distanceFilter properties of the location
manager and then call the requestLocation(), startUpdatingLocation(),
or allowDeferredLocationUpdates(untilTraveled:timeout:) method. Never
specify an accuracy value greater than what you need. Core Location
uses the accuracy value you specify to manage power better. A higher
degree of accuracy requires more precise hardware like GPS, which
consumes more power.
https://developer.apple.com/reference/corelocation/cllocationmanager
Your callback selector has to have a different signature:
class MyClass {
func startTimer() {
_timer = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(MyClass.timerCallBack(_:)), userInfo: nil, repeats: true)
}
// ...
func timerCallBack(timer: Timer) {
// Here you go.
}
}
(Maybe contain some syntax errors; currently don't have Xcode at hand)