我的目标iOS 7上的C应用程序从startUpdatingsignificantLocationChanges或startUpdatingLocation委托(取决于应用程序所在的模式,但我认为不重要)在后台获取位置更新。Firebase可以在iOS 7的后台发送和接收吗?
在委托中,我收集位置信息,将其写入字典,然后将字典写入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, @"Mode",
nil];
// Write it once to CurrentLocation
[ref setValue:dictionary];
// yes, I know this is clumsy
fbTmp = [NSMutableString stringWithString: fbRoot];
[fbTmp appendString : @"/locationHistory"];
ref = [[Firebase alloc] initWithUrl:fbTmp];
// Now write it again to the locationHistory list
ref = [ref childByAutoId];
[ref setValue:dictionary];
有时工作,有时不(即应用程序的相同的运行,有时位置被写入到火力地堡成功预期,并且有时没有,而且也没有任何明显的韵律或理由,当它似乎工作,当它不)。
我怀疑问题是Firebase写入在后台模式下没有成功完成,但我不确定。我对iOS和Objective C以及Firebase都很陌生。
我的应用程序在其功能中标记为需要位置更新和后台提取的后台服务(后者是我随机尝试解决此问题,前者我知道我需要)。
我怀疑我需要告诉操作系统我需要时间用backkgroundTask完成写入操作,然后在firebase写入的完成块中终止后台任务 - 任何人都会验证在运行时会起作用在后台模式?
如果是这样,我只需要在第二次写入时(假设它们按顺序完成)或两者都有(在每次写入完成时计数器计数)?
任何提示最受赞赏。
应用程序可以在后台执行哪些操作,而不是Firebase的权限。它保持连接一段任意长度,然后OS根据需要切断套接字连接。这可能说明了“有时候有作品”。 – Kato 2014-09-24 15:20:03