【发布时间】:2017-12-30 07:33:08
【问题描述】:
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 和设置选择器。但是我怎样才能将 lat/lng 参数发送到我的函数?
【问题讨论】:
-
您可以将您的位置作为类变量并发送
-
是的,我知道要通过选择器发送什么?
-
@pmb 你只需要去掉输入参数并直接在你的函数中使用类属性。请参阅下面的答案。
标签: ios swift swift3 core-location