我在iOS 7上的Objective C应用程序在后台从startUpdatingsignificantLocationChanges或startUpdatingLocation委托获取位置更新(哪一个取决于应用程序所处的模式,但我认为不重要).
在委托中,我收集位置信息,将其写入字典,然后将字典写入Firebase.
// this code is in the location update delegate routine
// the code that gathers the various elements that go into the dictionary
// are omitted for clarity, I don't think that they matter
// we may be running in the background on iOS 7 when we are called!
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[[NSNumber numberWithFloat:newLocation.coordinate.latitude] stringValue], @"Latitude",
[[NSNumber numberWithFloat:newLocation.coordinate.longitude] stringValue], @"Longitude",
[[NSNumber numberWithFloat:newLocation.horizontalAccuracy] stringValue], @"Accuracy",
formattedDateString, @"TimeNow",
[dateFormatter stringFromDate:newLocation.timestamp], @"TimeStamp",
[[NSNumber numberWithDouble:interval] stringValue], @"Date",
self.mode, …Run Code Online (Sandbox Code Playgroud)