【发布时间】:2016-04-07 10:16:21
【问题描述】:
我想从当前登录的用户那里获取所有位置记录。
这会在 CloudKit 上创建位置记录:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last!
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
addCrumbPoint(center)
let locationRecord = CKRecord(recordType: "location")
locationRecord["location"] = location
let publicData = CKContainer.defaultContainer().publicCloudDatabase
publicData.saveRecord(locationRecord) { record, error in
}
}
但是我将如何仅提取当前登录用户的位置记录?
我想用它在地图上创建以前旅程的面包屑,但只是让它打印一个列表将是一个很好的开始!
到目前为止,这是我的代码:
func getLocationAsync(complete: (instance: CKRecordID?, error: NSError?) -> ()) {
let container = CKRecordID(recordName: "Location")
publicDB.fetchRecordWithID(location) { fetchedLocation, error in
if error != nil {
print(error!.localizedDescription)
complete(instance: nil, error: error)
} else {
print("fetched Location \(recordID?.recordName)")
complete(instance: recordID, error: nil)
}
}
}
【问题讨论】: