我的目標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