Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In which folder do i have to save a data file in a IOS app?

Tags:

ios

iphone

I'm developing a QRCode reader app. When a qrcore is scanned I want to save it data in a file. I don't want to back it up in icloud, I just want that the data of file don't be lost when the app is closed.

so which folder should i save my data file?

thanks

like image 866
Alessandro Garcez Avatar asked Dec 05 '25 07:12

Alessandro Garcez


1 Answers

As per the iOS Data Storage Guidelines, you have options to store data in

  1. Documents - User generated data (non-reproducible)
  2. Caches - Cached content (reproducible)
  3. Temp - Temporary data (needs no persistence across sessions)
  4. Documents with no iCloud backup attribute

Decision to choose which place to store depends on the context of the app. If the QRCode file, needs to be there and is user specific opt for option 4. The data stored in caches directory can be purged if the device runs out of disk space.

NSString *documentsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

Please refer answer1 and answer2 for more details.

Thanks to Tommy, danh and The Tiger for making the answer more complete.

like image 172
Anupdas Avatar answered Dec 07 '25 20:12

Anupdas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!