func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let mostRecentLocation = locations.last else {
return
}
print(mostRecentLocation.coordinate.latitude)
print(mostRecentLocation.coordinate.longitude)
Timer.scheduledTimer(timeInterval: 60.0, target: self, selector: #selector(StartTestVC.sendDataToServer), userInfo: nil, repeats: true)
}
func sendDataToServer (latitude: Double, longitude: Double) {
SFUserManager.shared.uploadPULocation(latitude, longitude:longitude)
}
我希望每1分鐘向服務器發送一次數據。我正在使用Timer.scheduledTimer並設置選擇器。但我怎麼能發送經緯度/經度函數?如何在定時器選擇器上傳遞參數
你可以把你的位置作爲類變量,併發送 –
是的,我知道要通過選擇送? – pmb
@pmb你只需要擺脫輸入參數並直接在函數內部使用類屬性。請參閱下面的答案。 –