在委托中,我收集位置信息,将其写入字典,然后将字典写入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,有时它不会.没有任何明显的押韵或理由,当它似乎工作,什么时候不工作).
我怀疑问题是Firebase写入没有在后台模式下成功完成,但我不确定.我是iOS和Objective C和Firebase的新手.
我的应用程序在其功能中标记为要求位置更新和后台获取的后台服务(后者我随机尝试解决此问题,前者我知道我需要).
我的怀疑是我需要告诉 *** 作系统我需要时间来完成使用backkgroundTask的写入,然后在firebase写入的完成块中终止后台任务 – 有人确认在后台模式下运行时会有效吗?
如果是这样,我是否只需要在第二次写入(假设它们按顺序完成)或两者中都这样做(使用我在每次写入完成时倒计时的计数器)?
任何提示最受赞赏.
解决方法 是的,你需要在后台完成你的任务.它在 Apple Documentation中这样说:If your app is in the mIDdle of a task and needs a little extra time to complete that task,it can call the beginBackgroundTaskWithname:expirationHandler: or beginBackgroundTaskWithExpirationHandler: method of the UIApplication object to request some additional execution time. Calling either of these methods delays the suspension of your app temporarily,giving it a little extra time to finish its work. Upon completion of that work,your app must call the endBackgroundTask: method to let the system kNow that it is finished and can be suspended.
只需将您的代码放在后台任务中,给它最大的时间(我想3分钟).
阅读Apple app lifecycle,一切都应该清理,以备将来参考.
总结以上是内存溢出为你收集整理的Firebase可以在iOS 7的后台发送和接收吗?全部内容,希望文章能够帮你解决Firebase可以在iOS 7的后台发送和接收吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)