-1
我希望用戶的位置在cloudkit中更新,但我的代碼每次只保存一條新記錄。現有記錄如何修改或替換爲新記錄?試圖在swift中修改ckrecord
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.mapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
locationRecord.setObject(location, forKey: "location")
let publicData = CKContainer.defaultContainer().publicCloudDatabase
publicData.saveRecord(locationRecord) { record, error in
}
if error == nil
{
print("Location saved")
self.loc1 = location!
}
}
什麼是'locationRecord '? – matt
let locationRecord = CKRecord(recordType:「location」)@matt – Steve
嗯,這是你的問題。如果您想修改_existing_記錄,爲什麼要製作_new_記錄? – matt