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开发者_Python百科 directory takes a long time, though -- 8 seconds on my iPhone 3GS, even longer on my iPhone 3G, and on the first-gen iPod touch.
I write the file this way:
[imgData writeToFile:imagePath atomically:YES];
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.
- 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!
精彩评论