简体   繁体   English

将大量频繁的数据写入iOS中的文件?

[英]Writing large and frequent data to a file in iOS?

I would like to save data to a file every second. 我想每秒将数据保存到一个文件中。 The data records is simple, just a date and number, and would like to append to the file. 数据记录很简单,只是一个日期和数字,并且想要附加到文件中。 This can last the whole day, so the file can end up being big. 这可能会持续一整天,因此文件可能会很大。

I do not want to block the main thread, nor have concurrency issues. 我不想阻塞主线程,也没有并发问题。 It also has to be capable to being written to in the background, as opposed to the app being in the foreground. 与应用程序位于前台相反,它还必须能够在后台写入。

What's the best way forward to achieve this? 实现这一目标的最佳方法是什么?

You could use Core Data for this. 您可以为此使用核心数据。 Saving one item per second is not going to impact your app performance at all. 每秒节省一个项目根本不会影响您的应用程序性能。 Using Core Data will give you ability to query the data, so if you need to show chart from 10 AM to 11 AM from you 24 hours of data for example, it won't be a problem. 使用Core Data将使您能够查询数据,因此,例如,如果需要显示24小时数据中从10 AM到11 AM的图表,则不会有问题。

Background data collection capability depends on the data source. 后台数据收集功能取决于数据源。 For example, you can collect location updates in the background. 例如,您可以在后台收集位置更新。 The system provides tools to make this energy efficient. 该系统提供了使这种能源效率更高的工具。 Check http://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html 检查http://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

From the documentation : 文档中

The bluetooth-central Background Execution Mode 蓝牙中央背景执行模式

[...] While your app is in the background you can still discover and connect to peripherals, and explore and interact with peripheral data. [...]当您的应用程序在后台运行时,您仍然可以发现并连接到外围设备,并探索外围设备数据并与之交互。 In addition, the system wakes up your app when any of the CBCentralManagerDelegate or CBPeripheralDelegate delegate methods are invoked, allowing your app to handle important central role events, such as when a connection is established or torn down, when a peripheral sends updated characteristic values, and when a central manager's state changes. 此外,当调用任何CBCentralManagerDelegateCBPeripheralDelegate委托方法时,系统都会唤醒您的应用程序,从而使您的应用程序可以处理重要的中心角色事件,例如建立连接或断开连接时,外设发送更新的特征值时,以及中央管理者的状态发生变化时。 [...] [...]

To use it, just go to your Project Settings > Your Target > Capabilites, enable Background Modes and check "Uses Bluetooth LE accessories" 要使用它,只需转到“项目设置”>“目标”>“功能”,启用“背景模式”并选中“使用蓝牙LE配件”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM