0

I already have an sqlite file in my application. But in one of my application settings page there are two options restore and backup. The idea which is to be implemented is that a) On clicking backup the sqlite file which is already there must be saved in another folder inside the application by creating a new folder. b) On clicking restore the datas must be fetched from the sqlite file present in the newly created folder.

Any idea how to achieve this? Thanks

Ashley Rodrigues
  • 153
  • 2
  • 10
  • 1
    Backing up your data to another folder inside the same app sandbox is not a good idea. If someone deletes the app, the data and the backup will both be deleted. A backup needs to stored off of the device. – rmaddy May 09 '16 at 05:33
  • 1. You can't write anything in NSBundle 2. You need to use writable folders such as Documents folder 3. If you have pre-filled sqlite, you can easily copy the sqlite from NSBundle to new folder that you can create in Documents folder. 4. For all you need to look into `NSFileManager` operations [read this](http://www.techotopia.com/index.php/Working_with_Files_in_Objective-C). – iphonic May 09 '16 at 05:33
  • @iphonic so it means to copy sqlite file to the newly created folder in documents folder – Ashley Rodrigues May 09 '16 at 05:40
  • @AshleyRodrigues Yes, but according to above response, you should backup off device if you really want to keep a copy always for the user, for that you may need to upload the sqlite file to a server rather than copying locally, though you can do both for best use. – iphonic May 09 '16 at 05:42
  • @iphonic No dear just the basic idea is to store the file locally :) – Ashley Rodrigues May 09 '16 at 05:59
  • refer this link to get idea about sqlite db programmatically http://stackoverflow.com/questions/10545520/how-to-create-sqlite-database-programmatically –  May 09 '16 at 06:04

1 Answers1

0

You should use NSFileManager to copy the existing SQLite file to Document directory. Once the file is saved, attach it to Mail Composer view so user can have its backup in email. Register an URL scheme that can handle SQLite files so when user clicks on SQLite attachment your app can handle it in openURL method.

Nirav
  • 119
  • 7