在iPhone上写入大文件的最快方法? [英] Fastest way to write a large file on the iPhone?
问题描述
我正在使用的该应用程序允许用户拍照,并将其保存在本地(通过Core Data的小缩略图图像,以及在文档目录中的完整尺寸的图像).我发现将图像文件写入文档目录需要花费很长时间-在我的iPhone 3GS上是8秒,在我的iPhone 3G和第一代iPod touch上甚至更长.我这样写文件:
This app i'm working on allows the user to take pictures, and saves them locally (a small thumbnail image via Core Data, and the full-size image in the documents directory). I'm finding that writing the image file to the documents directory takes a long time, though -- 8 seconds on my iPhone 3GS, even longer on my iPhone 3G and first-gen iPod touch. I write the file this way:
[imgData writeToFile:imagePathatomic:YES];
[imgData writeToFile:imagePath atomically:YES];
...是否有更快的方法可以做到这一点?iPhone的相机应用程序似乎可以非常快速地将图像写入文件系统.我可以在线程中进行编写,但是我担心用户可能在线程完成之前退出我的应用程序.
... is there a faster way to do this? The iPhone's camera app seems to write the images to the filesystem very quickly. I could do the writing in a thread, but i'm concerned about the user possibly quitting my app before the thread finishes.
推荐答案
- 有人问了一个密切相关的问题
- 也许您应该确实尝试使用线程来保存图像,但是以面向数据的方式以字节块的形式保存图像.这样,如果用户在应用程序的委托的
-(无效)applicationWillTerminate(UIApplication *)application
方法中按下主页按钮,则可以完成将数据保存到磁盘的过程.这只会给您额外的5秒钟,但总比没有好.- A closely related question has been asked before, and the general opinion is that the iPhone's camera app uses undocumented internal API calls. I'm personally not sure if this is true, I think it's more likely that the iPhone app can persist in the background until the image is saved, a "commodity" not yet available to third party apps on non-jailbroken devices.
- Perhaps you should try indeed using a thread to save your image, but in a more data-oriented way, in byte chunks. This way, if the user presses the home button, in your
- (void) applicationWillTerminate(UIApplication *)application
method from the app's delegate, you could finalize the process of data saving to disk. This will only buy you an extra 5 seconds, though, but it's better than nothing at all. Similar recommendations have been given on saving a text file. Hope this helps, best of luck!
这篇关于在iPhone上写入大文件的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 也许您应该确实尝试使用线程来保存图像,但是以面向数据的方式以字节块的形式保存图像.这样,如果用户在应用程序的委托的