Lasse Madsen
Lasse Madsen

Reputation: 602

Store pictures on device

I want to store pictures taken from my app on the device, until it is uploaded. Even if the app is updated, the images should still be prevented on the device.

Where do I have to store the image?

The image should not be visible to the user, as it should not be possible for the user to delete it except from my app.

Upvotes: 1

Views: 49

Answers (2)

SushiHangover
SushiHangover

Reputation: 74144

Sounds like you want to use the Library directory for your use-case:

Library Directory:

var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
var library = Path.Combine (documents, "..", "Library");
var filename = Path.Combine (library, "WriteToLibrary.txt");
File.WriteAllText(filename, "Write this text into a file in Library");

The Library directory is a good place to store files that are not created directly by the user, such as databases or other application-generated files. The contents of this directory are never exposed to the user via iTunes.

You can create your own subdirectories in Library; however, there are already some system-created directories here that you should be aware of, including Preferences and Caches.

The contents of this directory (except for the Caches subdirectory) are backed up by iTunes. Custom directories that you create in Library will be backed up.

App Updates:

When a new version of your application is downloaded, iOS creates a new home directory and stores the new Application Bundle in it. iOS then moves the following folders from the previous version of your Application Bundle to your new home directory:

  • Documents
  • Library

Ref: https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system/

Upvotes: 2

Manoj
Manoj

Reputation: 1069

You can save the image to a local path(Documents folder). Delete once its uploaded. This will also prevent user interacting with the image.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"MYIMAGE.png"];
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];

Once you are done with uploading or any processing delete the image.

Upvotes: 1

Related Questions