我想在当前城市每次更改时触发通知didUpdateLocations
:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let lastLocation = locations.last!
updateLocation(location: lastLocation)
}
所以在这里我会比较城市是否发生了变化,并据此发送推送通知。我怎么能这样做?
func updateLocation(location: CLLocation) {
fetchCityAndCountry(from: location) { city, country, error in
guard let city = city, let country = country, error == nil else { return }
self.locationLabel.text = city + ", " + country
if(city !== previousCity){
//Send push notification
}
}
}
我知道我可以根据具有范围的位置触发它,但这对我来说不够具体。