记录到文件加速度计数据
我想添加一个Apple示例[AccelerometerGraph],能够将数据存储在文件中,直到应用程序未关闭。没有锁定问题和其他实时数据收集的蹩脚问题。
有什么想法、示例或半新手可以玩的东西吗?
I would like add a this Apple example [AccelerometerGraph] the ability to store the data in a file until the app isn't closed. Without locking issues and other crappy problems of real time data collection.
Any idea, sample or something that a semi newbie can play with?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在加速度计数据命中时将其记录到 NSMutableArray 中,然后当应用程序关闭时将该数组写入文件中:
只是想确保您不存储每个条目,否则它可能会很快变得很大。对加速对象中的时间戳进行一些检查,使其
每隔几秒记录一次,具体取决于您要运行它的时间。 (这种方法在不限制它的情况下长时间运行可能不明智,或者进行其他一些数组操作,以便在应用程序的整个生命周期中整个数组不会保存在内存中)
快速读取文件的方法已经写了。
you could log the accelerometer data into an NSMutableArray as it hits and then when the app is being closed write that array to a file with:
just want to make sure you dont store every single entry or it could get large very fast. Do some checking on the timestamp in the acceleration object in
make it log every couple of seconds depending on how long you are going to be running it. (this method would probably not be wise to run for long lengths of time without throttling it, or doing some other array manipulations so that the entire array isnt held in memory through out the life time of the app)
quick way to read the file you have written.
如果您只想查看输出的数据,您可以采用简单的方法将其记录到控制台。
在 MainViewController.m 中的 -(void)accelerometer: 方法中,只需添加
然后,当您在设备上运行它时,打开调试器控制台,它将为您流出数据。这是我得到的:
If you are just wanting to view the data as it comes out, you can do the simple way of just logging it to the console.
In MainViewController.m, in the -(void)accelerometer: method just add
Then when you run it on the device, open up the debugger console and it will stream out the data for you. Here is what I got: